Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.NullPointerException  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi everybody Just wrote this script:


When I compile there are no errors.
But when i run i get this error:

Exception in thread "main" java.lang.NullPointerException
at Database.main(Database.java:29)


Dont understand why.
Tia,
Bram
 
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

bram van gemert wrote:
Hi everybody Just wrote this script:


When I compile there are no errors.
But when i run i get this error:

Exception in thread "main" java.lang.NullPointerException
at Database.main(Database.java:29)


Dont understand why.
Tia,
Bram



Is line 25 meant to be a useless while? It looks odd to me at that point. Are you missing curly braces?
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The notes variable is initialized in the constructor. But no Database object is ever instantiated, so notes is still null. It's a static variable - why are you initializing it in a constructor?
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!