commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anna Klisiewicz" <anna.klisiew...@googlemail.com>
Subject Re: SCXML - getting started
Date Sat, 02 Aug 2008 15:49:24 GMT
Thanks Rahul for your answer. I have another problem now.

Whatever SCXML file I load I get NullPointerException. When I try the simple
hello world for example:

<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
       version="1.0"
       initialstate="hello">
   <state id="hello" final="true">
       <onentry>
           <log expr="'hello world'" />
       </onentry>
   </state>
</scxml>


I get:

Exception in thread "main" java.lang.NullPointerException

        at
org.apache.commons.scxml.SCInstance.getContext(SCInstance.java:181)
        at org.apache.commons.scxml.model.Log.execute(Log.java:102)
        at
org.apache.commons.scxml.semantics.SCXMLSemanticsImpl.executeActions(SCXMLSemanticsImpl.java:232)
        at
org.apache.commons.scxml.SCXMLExecutor.reset(SCXMLExecutor.java:252)
        at org.apache.commons.scxml.SCXMLExecutor.go(SCXMLExecutor.java:351)
        at dialoguesystem.Parser.Parser(Main.java:63)
        at dialoguesystem.Main.main(Main.java:24)
Java Result: 1

What am I doing wrong? This is the code I use:


-------------------------------------Code------------------------------------
package dialoguesystem;

import java.io.IOException;
import java.net.URL;
import org.apache.commons.scxml.io.SCXMLParser;
import org.apache.commons.scxml.model.ModelException;
import org.apache.commons.scxml.model.SCXML;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.apache.commons.scxml.SCXMLExecutor;
import org.apache.commons.scxml.PathResolver;
import org.apache.commons.scxml.Context;
import org.apache.commons.scxml.ErrorReporter;
import org.apache.commons.scxml.Evaluator;
import org.apache.commons.scxml.EventDispatcher;
import org.apache.commons.scxml.SCXMLListener;




public class Main{
   public static void main(String[] args) {
      Parser parse = new Parser();
      parse.Parser();
     }
 }

 class Parser {

     private URL xml;
     private ErrorHandler errHandler;
     private PathResolver pathResolver;
     private SCXML scxml = null;
     private SCXMLExecutor exec;
     private Evaluator expEvaluator;
     private EventDispatcher evtDisp;
     private ErrorReporter errRep;
     private SCXMLListener scxmlListener;
     private Context rootContext;




 public void Parser(){
     Thread.currentThread().setContextClassLoader
(this.getClass().getClassLoader());
     xml =
this.getClass().getClassLoader().getResource("resources/hello.xml");
     try {
        scxml = SCXMLParser.parse(xml, errHandler);
        } catch (IOException io) {
        } catch (SAXException se) {
        } catch (ModelException me) {
        }


        exec = null;
        try {
            exec = new SCXMLExecutor(expEvaluator, evtDisp, errRep);
                    if (exec != null) {
                   System.out.println("Co!!!!\n");}
            exec.setStateMachine(scxml);
            exec.addListener(scxml, scxmlListener);
            exec.setRootContext(rootContext);
            exec.go();
            } catch (ModelException me) {
        }
     }
    }

--------------------------------------------

Thank you in advance,
Anna

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message