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 <-
//          ctx.error (error)
//        for (warning <-
//          ctx.error (warning)

//        if (! issues.getErrors.isEmpty)
// ("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(
	at org.eclipse.xtext.parser.antlr.XtextTokenStream.<init>(
	at prompt.parser.antlr.PromptParser.parse(
	at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.parse(
	at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(
	at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(
	at org.eclipse.xtext.parser.AbstractParser.parse(
	at org.eclipse.xtext.parser.SwitchingParser.parse(
	at org.eclipse.xtext.resource.XtextResource.doLoad(
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLoad(
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(
	at ex.Ex.readModel(
	at ex.Ex.main(

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/
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
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...


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: Sun Sep 20 19:03:42 GMT 2020

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

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

Back to the top