[rules-users] Error is Java.lang.RuntimeException

Manohar Kokkula manohar.kokkula at tcs.com
Thu Aug 25 09:57:04 EDT 2011


Hi, 

I tried that also, kept RuleTable and the Rule name initial in one cell, 
but I am encountering the same errors. 

I re-created the Application, but I am not able to run it properly. 

When I check the generated drl string, it seems fine to me. It would be 
very helpful, if I get guidance on this. I am not able to find out what is 
going wrong in this case...


Student.java and College.java are normal POJOs with variables and getter 
and setter methods.


My Main class:

public class AllocationClass {
 
        public static void main(String[] args) {
 
                Student s1  = new Student();
                College c1 = new College();
 
                s1.setMarks(70);
                s1.setAge(20);
                c1.setRanking("A");
                c1.setLocation("Delhi");
 
 
                try{
 
                KnowledgeBase kb = fromFunction();
                StatefulKnowledgeSession ks = 
kb.newStatefulKnowledgeSession();
 
                ks.insert(s1);
                ks.insert(c1);
                ks.fireAllRules();
 
                System.out.println("Department is  : 
"+s1.getDepartment());
                System.out.println("Status is : "+c1.getStatus());
 
                ks.dispose();
                }
                catch (Exception ex)
                {
                        System.out.println(" In main method......."+ ex);
                        ex.printStackTrace();
                }
 
 
 
        }
 
 
 
        private static KnowledgeBase fromFunction()
        {
                DecisionTableConfiguration dc = 
KnowledgeBuilderFactory.newDecisionTableConfiguration();
                dc.setInputType(DecisionTableInputType.XLS);
 
                KnowledgeBuilder kbd = 
KnowledgeBuilderFactory.newKnowledgeBuilder();
 kbd.add(ResourceFactory.newClassPathResource("com/sample/allocate.xls"), 
ResourceType.DTABLE,dc);
 
                String drlString = null;
                try {
                        drlString = 
DecisionTableFactory.loadFromInputStream(ResourceFactory.newClassPathResource("com/sample/allocate.xls").getInputStream(), 
dc);
                } catch (IOException e) {
                        e.printStackTrace();
                }
 
                  System.out.println("..........."+drlString);
 
 
        if(kbd.hasErrors())
                {
                        RuntimeException r1 =  new 
RuntimeException(kbd.getErrors().toString());
                        r1.printStackTrace();
                }
 
                KnowledgeBase kb = 
KnowledgeBaseFactory.newKnowledgeBase();
                kb.addKnowledgePackages(kbd.getKnowledgePackages());
 
                return kb;
        }

}


The xls that I have created : 


RuleSet
com.sample




Import
com.sample.Student,com.sample.College










RuleTable Allocation Rules





CONDITION
CONDITION
CONDITION
CONDITION
ACTION
ACTION
$s:Student
$c:College


marks
age
ranking
location
$s.setDepartment(?$param?);
$c.setStatus(?$param?);
Student Marks
Student Age
College Ranking
College Location
Department Allocated
Status Allocated
60
20
A
Mumbai
Maths
NA
86
22
B
Kolkata
Arts
Approved
70
20
A
Delhi
Science
Approved











The drlString that gets generated is : 

...........package com.sample;
#generated from Decision Table
import com.sample.Student;
import com.sample.College;
#From row number: 10
rule "Allocation Rules_10"
 
        when
                $s:Student(marks == "60", age == "20")
                $c:College(ranking == "A", location == "Mumbai")
        then
                $s.setDepartment(?Maths?);
                $c.setStatus(?NA?);
end

#From row number: 11
rule "Allocation Rules_11"
 
        when
                $s:Student(marks == "86", age == "22")
                $c:College(ranking == "B", location == "Kolkata")
        then
                $s.setDepartment(?Arts?);
                $c.setStatus(?Approved?);
end

#From row number: 12
rule "Allocation Rules_12"
 
        when
                $s:Student(marks == "70", age == "20")
                $c:College(ranking == "A", location == "Delhi")
        then
                $s.setDepartment(?Science?);
                $c.setStatus(?Approved?);
end



The output Error that I get is : 

java.lang.RuntimeException: 
[12,19]: [ERR 101] Line 12:19 no viable alternative at input ''[12,25]: 
[ERR 101] Line 12:25 no viable alternative at input ''[13,15]: [ERR 101] 
Line 13:15 no viable alternative at input ''[13,18]: [ERR 101] Line 13:18 
no viable alternative at input ''[23,19]: [ERR 101] Line 23:19 no viable 
alternative at input ''[23,24]: [ERR 101] Line 23:24 no viable alternative 
at input ''[24,15]: [ERR 101] Line 24:15 no viable alternative at input 
''[24,24]: [ERR 101] Line 24:24 no viable alternative at input ''[34,19]: 
[ERR 101] Line 34:19 no viable alternative at input ''[34,27]: [ERR 101] 
Line 34:27 no viable alternative at input ''[35,15]: [ERR 101] Line 35:15 
no viable alternative at input ''[35,24]: [ERR 101] Line 35:24 no viable 
alternative at input ''
 
at com.sample.AllocationClass.fromFunction(AllocationClass.java:75)
at com.sample.AllocationClass.main(AllocationClass.java:31)

Department is  :  null
Status is : null




Regards,
Manohar Kokkula
Mailto: manohar.kokkula at tcs.com



From:
Wolfgang Laun <wolfgang.laun at gmail.com>
To:
Rules Users List <rules-users at lists.jboss.org>
Date:
08/25/2011 05:19 PM
Subject:
Re: [rules-users] Error is Java.lang.RuntimeException
Sent by:
rules-users-bounces at lists.jboss.org



The cell with the keyword RuleTable must also contain the string for the 
initial part of the rule name. It seems that you have this in the 
adjoining cell. - See the docs, section "Rule Tables".
-W

2011/8/25 Manohar Kokkula <manohar.kokkula at tcs.com>
Hi Frank and Wolfgang, 
  
Thank you for your help, 
I did everything as you both said,still i am getting the same error, 


java.lang.RuntimeException: [12,19]: [ERR 101] Line 12:19 no viable 
alternative at input ''[12,27]: [ERR 101] Line 12:27 no viable alternative 
at input ''[13,15]: [ERR 101] Line 13:15 no viable alternative at input 
''[13,21]: [ERR 101] Line 13:21 no viable alternative at input ''[23,19]: 
[ERR 101] Line 23:19 no viable alternative at input ''[23,27]: [ERR 101] 
Line 23:27 no viable alternative at input ''[24,15]: [ERR 101] Line 24:15 
no viable alternative at input ''[24,21]: [ERR 101] Line 24:21 no viable 
alternative at input ''[34,19]: [ERR 101] Line 34:19 no viable alternative 
at input ''[34,25]: [ERR 101] Line 34:25 no viable alternative at input 
''[35,15]: [ERR 101] Line 35:15 no viable alternative at input ''[35,21]: 
[ERR 101] Line 35:21 no viable alternative at input ''[45,19]: [ERR 101] 
Line 45:19 no viable alternative at input ''[45,27]: [ERR 101] Line 45:27 
no viable alternative at input ''[46,15]: [ERR 101] Line 46:15 no viable 
alternative at input ''[46,21]: [ERR 101] Line 46:21 no viable alternative 
at input '' 
Error in kbuildefr ...... 
Error in main ... 
Error is java.lang.RuntimeException: [12,19]: [ERR 101] Line 12:19 no 
viable alternative at input ''[12,27]: [ERR 101] Line 12:27 no viable 
alternative at input ''[13,15]: [ERR 101] Line 13:15 no viable alternative 
at input ''[13,21]: [ERR 101] Line 13:21 no viable alternative at input 
''[23,19]: [ERR 101] Line 23:19 no viable alternative at input ''[23,27]: 
[ERR 101] Line 23:27 no viable alternative at input ''[24,15]: [ERR 101] 
Line 24:15 no viable alternative at input ''[24,21]: [ERR 101] Line 24:21 
no viable alternative at input ''[34,19]: [ERR 101] Line 34:19 no viable 
alternative at input ''[34,25]: [ERR 101] Line 34:25 no viable alternative 
at input ''[35,15]: [ERR 101] Line 35:15 no viable alternative at input 
''[35,21]: [ERR 101] Line 35:21 no viable alternative at input ''[45,19]: 
[ERR 101] Line 45:19 no viable alternative at input ''[45,27]: [ERR 101] 
Line 45:27 no viable alternative at input ''[46,15]: [ERR 101] Line 46:15 
no viable alternative at input ''[46,21]: [ERR 101] Line 46:21 no viable 
alternative at input '' 

        at com.model.Student_College.readBase(Student_College.java:90) 
        at com.model.Student_College.main(Student_College.java:31) 


Now i am sending my main class and .xls file. 

public class Student_College { 
        
        public static void main(String args[]) throws IOException 
        { 
                
                Student s=new Student(); 
                College c=new College(); 
                s.setAge(20); 
                s.setMarks(35); 
                c.setRanking("B"); 
                c.setLocation("elhi"); 
                
                
                
                try 
                { 
                        KnowledgeBase kbase = readBase(); 
                        StatefulKnowledgeSession ksession  = 
kbase.newStatefulKnowledgeSession(); 
                        
                        ksession.insert(s); 
                        ksession.insert(c); 
                        ksession.fireAllRules(); 
                        System.out.println("Department is 
"+s.getDepartment()); 
                        
                        System.out.println("Status is " + c.getStatus()); 
                          
                        ksession.dispose(); 
                        
                        
                        
                } 
                catch(RuntimeException re) 
                { 
                        System.out.println("Error in main ..."); 
                        re.printStackTrace(); 
                        System.out.println("Error is "+re); 
                        
                } 
                
        } 
        
        private static KnowledgeBase readBase() throws IOException 
        { 
                DecisionTableConfiguration dconf = 
KnowledgeBuilderFactory.newDecisionTableConfiguration(); 
                dconf.setInputType(DecisionTableInputType.XLS); 
                
                KnowledgeBuilder kbuilder = 
KnowledgeBuilderFactory.newKnowledgeBuilder(); 
                
kbuilder.add(ResourceFactory.newClassPathResource("manohar.xls", 
Student_College.class), ResourceType.DTABLE, dconf); 
                

            if(kbuilder.hasErrors()) 
                { 
                        System.out.println("Error in kbuildefr ......"); 
                        throw new 
RuntimeException(kbuilder.getErrors().toString()); 
                        
                } 
                
                KnowledgeBase kbase = 
KnowledgeBaseFactory.newKnowledgeBase(); 
                
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); 
                  
                return kbase; 
                
                
        } 

} 


In above main class i used the following code to interpret my manohar.xls 
file... 

String drlString = null; 
                try { 
                        drlString = 
DecisionTableFactory.loadFromInputStream(ResourceFactory.newClassPathResource("manohar.xls", 
Student_College.class).getInputStream(), dconf); 
                } catch (IOException e) { 
                        // TODO Auto-generated catch block 
                        System.out.println("Error in drl String ....."); 
                        e.printStackTrace(); 
                } 
                  
                  System.out.println("..........."+drlString); 




manohar.xls: 

RuleSet 
com.model 




Import 
com.model.Student, com.model.College 










RuleTable 
Allocation Rule 




CONDITION 
CONDITION 
CONDITION 
CONDITION 
ACTION 
ACTION 
$s:Student 
$c:College 


age 
marks 
ranking 
location 
$s.setDepartment(?$param?); 
$c.setStatus(?$param?); 






18
85
A 
Delhi 
Science 
AICTE 
18
90
B 
Kanpur 
Science 
AICTE 
20
90
A 
Mumbai 
Maths 
AICTE 
23
87
C 
Hyderabad 
Physics 
AICTE
















































































Thanks and Regards
Manohar Kokkula
Mailto: manohar.kokkula at tcs.com
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 

not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 

please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110825/5f2c705a/attachment.html 


More information about the rules-users mailing list