commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rahul Akolkar" <rahul.akol...@gmail.com>
Subject Re: SCXML - getting started
Date Sat, 02 Aug 2008 18:21:22 GMT
My response below ...

On Sat, Aug 2, 2008 at 11:49 AM, Anna Klisiewicz
<anna.klisiewicz@googlemail.com> wrote:
> 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) {
>        }
>     }
>    }
>
<snip/>

Most of the references in the above try block start off as being null,
and unless there is additional code, that doesn't seem to change.

Place the following lines just above the try block (you can import the
classes to avoid having to use the fully qualified names):

  expEvaluator = new org.apache.commons.scxml.env.jexl.JexlEvaluator();
  evtDisp = new org.apache.commons.scxml.env.SimpleDispatcher();
  errRep = new org.apache.commons.scxml.env.SimpleErrorReporter();
  scxmlListener = new org.apache.commons.scxml.env.SimpleSCXMLListener();
  rootContext = new org.apache.commons.scxml.env.jexl.JexlContext();

I have some other comments about the code, but lets wait a bit on that
and get the hello world example going for you first.

-Rahul


> --------------------------------------------
>
> Thank you in advance,
> Anna
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message