Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Null Pointer Exception - ANTLR TreeWalker

I keep getting a NullPoiterException in my TreeWalker but I can't seem to find out why.

I can't post the whole grammar, cause it's far too long.

This is the rule in the treeWalker where antlrWorks says the problem is:

collection_name returns [MyType value]
    : ID { $value = (MyType) database.get($collection_name.text); }
    ;

Note that database is a HashMap.

Thank you!

Answer*

Cancel
3
  • Yes, you are right ,I obviously did not poste enough code. Anyway, that is not the problem. The problem is that somehow my AST is not parsed how it should be. Commented Aug 22, 2012 at 17:36
  • The problem was that in a treeGrammar you can't do something like $collection_name.text , as you would in a parser grammar. That was the whole problem. I spent hours thinking my AST is wrong and trying to fix it. Thank you for your help! Commented Aug 22, 2012 at 23:21
  • @user1550876, cool, I somehow read over the fact that it was a tree tree! Good to hear you resolved it.
    – Bart Kiers
    Commented Aug 23, 2012 at 6:24