Bookmark Topic Watch Topic
  • New Topic

Null Pointer exception when accessing a static instantiated object with in the instance of  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am facing one weird problem when accessing a static object instance,

Test.java:



Run.java



On running Run it gives me a NPE,

[jkalyana@toddler ~]$ javac Test.java
[jkalyana@toddler ~]$ vim Run.java
[jkalyana@toddler ~]$ javac Run.java
[jkalyana@toddler ~]$ java Run
Exception in thread "main" java.lang.ExceptionInInitializerError
at Run.main(Run.java:3)
Caused by: java.lang.NullPointerException
at Test.enter(Test.java:10)
at Test.<init>(Test.java:7)
at Test.<clinit>(Test.java:4)
... 1 more


I had a doubt and changed the Test.java to this,



On moving the declaration of Test below map, it runs,

[jkalyana@toddler ~]$ java Run
Key = dummy1, Value = dummy2

Can anyone tell me why this is so.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Pleaseuse one thread per question. Let's continue here.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!