Question

im trying to define a simple function in drools :

function void difference(List<String> fileOld, List<String> fileNew)
{

   ArrayList<String> add = new ArrayList<String>(fileNew);
   add.removeAll(fileOld);
   System.out.println("files Added: " + add);

   ArrayList<String> remove = new ArrayList<String>(fileOld);
   remove.removeAll(fileNew);
   System.out.println("files Removed: " + remove);
 }   

but it says Unable to resolve type List while building function. java.lang.ClassNotFoundException: Unable to find class 'List' ] Cannot make a static reference to the non-static method getFileOld() from the type FileData Cannot make a static reference to the non-static method getFileNew() from the type FileData

My rules are:

rule "files are equal"

when 
    FileData(fileOld == fileNew)        

then
   System.out.println("files are equal");
end

rule "files not equal"
when
    not FileData(fileOld == fileNew)
then
   System.out.println("files are not equal");
   difference(FileData.getFileOld(),FileData.getFileNew()); 
end

fileOld and fileNew are the list of filenames in a folder at two different instances. im trying to find the difference between fileOld and fileNew and display the list of files added/deleted.

Was it helpful?

Solution

Unable to find class 'List' ] Cannot make a static reference to the non-static method getFileOld() from the type FileData Cannot make a static reference to the non-static method getFileNew() from the type FileData

From above statements in your question , it seems you are accessing nonstatic methods by FileData (I think its a class).If methods are nonstatic then you cant access your methods lisk this

Classname.nonstatic_method (not-allowed)

Classname.static_method (allowed)

Try your code by making your both methods static. OR make object of FileData and then access nonstatic methods

OTHER TIPS

In DRL, the situation is very much as it is in Java. You use either "import" or the full class name:

import java.util.List
import java.util.ArrayList



function void difference(java.util.List<String> fileOld, 
                         java.util.List<String> fileNew)

It doesn't hurt to read the Drools documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top