问题
I have defined some rules in DRL file, and its my first program of creating a drl file. I am getting the error "unable to analyse expression".Here is my code:
package rules
import com.sample.Applicant.appli;
rule "Is of valid age"
when
$a : appli ( age < 18 ) // appli is my class name
// age is a variable in that class
then
$a.setValid( false ); // setValid is a method of appli
end
and getting the error:
Unable to Analyse Expression age < 18:
[Error: unable to resolve method using strict-mode: com.sample.Applicant$appli.age()]
[Near : {... age < 18 ....}]
^
[Line: 16, Column: 4] : [Rule name='Is of valid age']
回答1:
Make sure in the class appli
, age
is either public or has a public getAge()
method.
回答2:
Even I was getting similar error 'Unable to Analyse Expression....' while validating a DRL file in Drools Workbench 6.4.0 Final. I checked Data Object, its fields, access specifier of the setters and getters. All seemed OK. Then I saved my data object and came back to DRL file and did validating. Suddenly the above error was gone and I saw message 'Successfully Validated'. My mistake was though I had created the Data Object in Drools Workbench, I had forgotten to save it by clicking 'Save' button.
So I would suggest you, if you are 100% sure that your Data Object and DRL files are correct, save these first and then validate DRL file again.
来源:https://stackoverflow.com/questions/18045403/drools-unable-to-analyse-expression