This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NullPointerException" Watch "Exception in thread "main" java.lang.NullPointerException" New topic
Author

Exception in thread "main" java.lang.NullPointerException

bram van gemert
Greenhorn

Joined: Oct 06, 2011
Posts: 4

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
Adam Cripps
Ranch Hand

Joined: Oct 01, 2011
Posts: 41

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?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.lang.NullPointerException
 
Similar Threads
Java-Xml file not getting Connected to DataBase
Unable to connect to MS SQL Server using JRun drivers
Null Pointer Exception
Can't write UTF8 chars
doubt having servlet connect to oracle XE database