2 Replies Latest reply on May 24, 2011 5:59 AM by stellina_rosa

    Unable to create Field Extractor

    stellina_rosa Newbie
      Hi!
      I'm trying to create an example Drools file but when I run it I have this error message:
      Unable to create Field Extractor for 'contenuto' of '[ClassObjectType class="java".lang.Object]' in rule 'prova' : [Rule name='prova']

       

       

      java.lang.IllegalArgumentException: Could not parse knowledge.

                at org.drools.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:58)

                at com.sample.ProcessTest.readKnowledgeBase(ProcessTest.java:43)

                at com.sample.ProcessTest.main(ProcessTest.java:21)

       

       

      this is my drools file (named Rule.drl):

       

      package com.googlecode.cursos.jbpm

      import org.drools.runtime.process.WorkflowProcessInstance;

      import org.sample.model.MyObject;

       

       

      rule "prova"

                ruleflow-group "regole"

                when

                          $o: Object(contenuto == "rosa")

                then

                 System.out.println("prima regola");

       

      end

       

       

      this is my ProcessTest.java class:

       

      public class ProcessTest {

       

       

                public static final void main(String[] args) {

                          try {

                                    // load up the knowledge base

                                    KnowledgeBase kbase = readKnowledgeBase();

                                    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                                    KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");

       

                                    MyObject obj = new MyObject();

                                    obj.setContenuto("rosa");

                                    obj.setId(1);

                                    ksession.insert(obj);

                                    // start a new process instance

                                    ksession.startProcess("com.sample.bpmn.hello");

       

                                    ksession.fireAllRules();

                                    logger.close();

                          } catch (Throwable t) {

                                    t.printStackTrace();

                          }

                }

       

      private static KnowledgeBase readKnowledgeBase() throws Exception {

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2);

        kbuilder.add(ResourceFactory.newClassPathResource("Rule.drl"), ResourceType.DRL);

        return kbuilder.newKnowledgeBase();

        }

       

       

      and this is my MyObject.java class:

       

      package org.sample.model;

       

      public class MyObject {

       

                String contenuto;

                int id;

                public int getId() { return id;}

      public void setId(int id) { this.id = id; }

      public String getContenuto() { return contenuto; }

      public void setContenuto(String contenuto) { this.contenuto = contenuto;}

      }


       

       

      I can't understand where is the problem

      could anyone help me please?

      thank you!