[stringtemplate-interest] [RE:] Re: NullPointerException from stgroup.getInstance()
Terence Parr
parrt at cs.usfca.edu
Tue Jun 21 11:12:58 PDT 2011
well, you really want
decl(title, body) ::= ...
right? ;)
no errors other than NPE?
T
On Jun 21, 2011, at 10:35 AM, Daniel Brenner wrote:
> hi Ter,
>
> tried it. Now, "decl.st" looks like
>
> t(args) ::= <<
> <html>
> <head>
> <title>$title$</title>
> </head>
> <body>
> <h1>$title$</h1>
> </body>
> </html>
>>>
>
> and it still keeps giving me the NPE.
>
> Cheers,
>
> - Daniel
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Terence Parr mailto:parrt at cs.usfca.edu
> Gesendet: 21.06.2011 19:28:10
> An: Daniel Brenner mailto:daniel.brenner at cas.de
> Cc: mailto:stringtemplate-interest at antlr.org
> Betreff: [RE:] Re: [stringtemplate-interest] NullPointerException from stgroup.getInstance()
>
> hi. do you have a header in each .st file? I might make a backward compat thing but you need a formal header for now
>
> t(args) ::= <<
> template
> >>
>
> T
> On Jun 21, 2011, at 4:51 AM, Daniel Brenner wrote:
>
> > Hi everybody,
> >
> > after a long time I want to use stringtemplate in one of my projects againg. I worked with stringtemplate v2 and the early versions of 3. However, it seems that I cannot get v4 working.
> >
> > This is my scenario:
> > In the folder "content/" there is the template file "decl.st" containing a very easy HTML page
> >
> > <html>
> > <head>
> > <title>$title$</title>
> > </head>
> > <body>
> > <h1>$title$</h1>
> > </body>
> > </html>
> >
> >
> > The source code with stringtemplate v3 is this
> >
> > StringTemplateGroup group = new StringTemplateGroup(null, "content/", DefaultTemplateLexer.class);
> > StringTemplate template = group.getInstanceOf("decl");
> > template.setAttribute("title", "Hello World");
> >
> > And it works perfectly fine.
> >
> > The equivalent in stringtemplate v4 (4.0.2) is - from what I figured and please correct me if I am wrong -
> >
> > STGroup group = new STGroupDir("content", '$', '$');
> > ST template = group.getInstanceOf("decl");
> > template.add("title", "Hello World");
> >
> > Now when I run this, I am seeing a NullPointerException:
> >
> > Exception in thread "main" java.lang.NullPointerException
> > at org.stringtemplate.v4.STGroup.loadTemplateFile(STGroup.java:624)
> > at org.stringtemplate.v4.STGroupDir.loadTemplateFile(STGroupDir.java:165)
> > at org.stringtemplate.v4.STGroupDir.load(STGroupDir.java:127)
> > at org.stringtemplate.v4.STGroup.lookupTemplate(STGroup.java:226)
> > at org.stringtemplate.v4.STGroup.getInstanceOf(STGroup.java:160)
> > at Fancy.main(Fancy.java:15)
> >
> > Also with stringtemplate v4.0.3 I am seeing the NPE.
> >
> > What did I do wrong? I want to use v4 because of its cool new feature.
> >
> > Alongside with the NullPointerException I get the following output in my eclipse console:
> >
> > decl.st 1:1: invalid character '<'
> > decl.st 1:5: invalid character '>'
> > decl.st 2:1: invalid character '<'
> > decl.st 1:1: no viable alternative at input 'html'
> > decl.st 2:5: invalid character '>'
> > decl.st 3:1: invalid character '<'
> > decl.st 3:6: invalid character '>'
> > decl.st 3:7: invalid character '$'
> > decl.st 3:13: invalid character '$'
> > decl.st 3:15: invalid character '<'
> > decl.st 3:16: invalid character '/'
> > decl.st 3:21: invalid character '>'
> > decl.st 4:1: invalid character '<'
> > decl.st 4:2: invalid character '/'
> > decl.st 4:6: invalid character '>'
> > decl.st 5:1: invalid character '<'
> > decl.st 5:5: invalid character '>'
> > decl.st 6:1: invalid character '<'
> > decl.st 6:3: invalid character '>'
> > decl.st 6:4: invalid character '$'
> > decl.st 6:10: invalid character '$'
> > decl.st 6:12: invalid character '<'
> > decl.st 6:13: invalid character '/'
> > decl.st 6:15: invalid character '>'
> > decl.st 7:1: invalid character '<'
> > decl.st 7:2: invalid character '/'
> > decl.st 7:6: invalid character '>'
> > decl.st 8:1: invalid character '<'
> > decl.st 8:2: invalid character '/'
> > decl.st 8:6: invalid character '>'
> >
> > What is this all about?
> >
> > Thanks in advance and cheers,
> >
> > - Daniel
> >
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list