Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » NullPointerException reading Xtext model outside of Eclipse
NullPointerException reading Xtext model outside of Eclipse [message #514869] Tue, 16 February 2010 23:27 Go to next message
Arno Haas is currently offline Arno HaasFriend
Messages: 4
Registered: July 2009
Junior Member
I want to use Xtext to read a model in a stand-alone Java application, i.e. outside of Ecplise and not using OSGi. The following code works fine if I start it inside Eclipse, but it throws a NPE when I start it outside Eclipse (the commented out code stands for variations I tried - they all yielded the identical exception).

    public static EObject readModel (String filename) throws IOException {
        final Injector injector = new PromptStandaloneSetup().createInjectorAndDoEMFRegistration();

        // final IParser parser = injector.getInstance(IParser.class);


        final ResourceSet set = injector.getInstance(XtextResourceSet.class);
        final Resource res = set.getResource(URI.createURI (filename), true);

        return res.getContents().get(0);

        //return ModelUtils.load (filename, set);

        //new StandaloneSetup();

        /*
        final MweReader reader = new MweReader();
        reader.setUri (filename);
        reader.setRegister (new prompt.PromptStandaloneSetup ());
        reader.setOutputSlot ("model");

        final WorkflowContextDefaultImpl context = new WorkflowContextDefaultImpl();
        final IssuesImpl issues  = new IssuesImpl ();
        reader.invoke (context, null, issues);

//        for (error <- issues.getErrors.map(_.getMessage))
//          ctx.error (error)
//        for (warning <- issues.getWarnings.map(_.getMessage))
//          ctx.error (warning)

//        if (! issues.getErrors.isEmpty)
//          ctx.fail ("errors while parsing model")

        return (EObject) context.get ("model");
        */
    }


The stacktrace is as follows:

Exception in thread "main" java.lang.NullPointerException
	at org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider.getTokenDefMap(AntlrTokenDefProvider.java:64)
	at org.eclipse.xtext.parser.antlr.XtextTokenStream.<init>(XtextTokenStream.java:50)
	at prompt.parser.antlr.PromptParser.parse(PromptParser.java:27)
	at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.parse(AbstractAntlrParser.java:51)
	at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(AbstractAntlrParser.java:34)
	at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(AbstractAntlrParser.java:1)
	at org.eclipse.xtext.parser.AbstractParser.parse(AbstractParser.java:27)
	at org.eclipse.xtext.parser.SwitchingParser.parse(SwitchingParser.java:49)
	at org.eclipse.xtext.resource.XtextResource.doLoad(XtextResource.java:151)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLoad(LazyLinkingResource.java:43)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1494)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1282)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
	at ex.Ex.readModel(Ex.java:48)
	at ex.Ex.main(Ex.java:79)


I used the following classpath (using Xtext 0.8 shows the same behaviour):

export CLASSPATH=myproject/out/production/emf-read
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.xtext.util_0.7.2.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.xtext.log4j_1.2.15.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/com.google.collect_0.8.0.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.ecore.xmi_2.5.0.v200906151043.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.mwe.utils_0.7.2.v200908120417.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.ecore_2.5.0.v200906151043.jar
export CLASSPATH=$CLASSPATH:myproject/lib/oro-2.0.6.jar
export CLASSPATH=$CLASSPATH:myproject/lib/aopalliance.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.apache.commons.logging_1.0.4.v200904062259.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.common_2.5.0.v200906151043.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.xtext_0.7.2.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/antlr-runtime-3.0.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.mwe.core_0.7.2.v200908120417.jar
export CLASSPATH=$CLASSPATH:myproject/lib/guice-1.0_patched.jar 


Any ideas / help is appreciated!

Re: NullPointerException reading Xtext model outside of Eclipse [message #514881 is a reply to message #514869] Wed, 17 February 2010 00:24 Go to previous messageGo to next message
Arno Haas is currently offline Arno HaasFriend
Messages: 4
Registered: July 2009
Junior Member
Debugging showed that the *.token file had not been copied from the source folder to the classpath. Fixed that, now it works just fine.
Re: NullPointerException reading Xtext model outside of Eclipse [message #901683 is a reply to message #514881] Tue, 14 August 2012 07:08 Go to previous message
Philipp M. Fischer is currently offline Philipp M. FischerFriend
Messages: 67
Registered: November 2010
Location: Germany
Member
I had the same issue when creating my plugins using a mven build process...

I forgot to copy the *.g and *.tokens file into my plugin...

Make sure they are present and things should be fine...

Cheers

Phil Smile
Previous Topic:2 DSLs, importURI + importedNamespace in one grammar?
Next Topic:Cross referencing to an attribute of an instance of a class
Goto Forum:
  


Current Time: Thu Apr 18 15:31:06 GMT 2024

Powered by FUDForum. Page generated in 0.02202 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top