• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.NullPointerException  RSS feed

 
Craig Giles
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to connect to a oracle database and display some data. Not sure where the "Parm" is coming from.

Here is the error:

Parm
Exception in thread "main" java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at DatabaseExample.ConnectionManager.makeConnection(ConnectionManager.java:35)
at DatabaseExample.DatabaseService.getEmployee(DatabaseService.java:45)
at DatabaseExample.DatabaseService.main(DatabaseService.java:98)

The program uses 5 files, not sure how many I should post. Here is the one that outputs the records selected.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace indicates that the error happens in the ConnectionManager class, but you haven't shown us the code for that. It looks like you're passing "null" to Class.forName() on line 35. Presumably the database connection string is supposed to come from somewhere, but it's not getting initialized.

Incidentally, why do you have this:



instead of simply

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



This shows the error at ConnectionManager Class. show that please.
 
Craig Giles
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the Connection Manager class


Herer is the parm.properties file


and the Parm.java
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Couple of things to check ,

Is your param.properties in loaded to Properties object properly ? because static initialiser is not recommended way and not sure if there is a exception , it reports where ??!? , so constructor or static method is pretty safe



make sure there are no additional spaces or any other characaters after "OracleDriver" , some additional spaces may lead to such beahviour. you can use trim() to eliminate such behaviour.

(String) props.getProperty(pVariable)).trim();
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu Sadhasivam wrote:it reports where ??!?

To System.out apparently, because that's where the caught exceptions are written out to.


You do know that a) the class name is DatabaseExample.Parm, not just Parm, and b) you can simply use Parm.class?

Because you're using the wrong class name, a ClassNotFoundException is thrown, with message "Parm" - the class that could not be found. That's also where that printed Parm came from: System.out.println(cnfe.getMessage());
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and that's also why the code never even attempts to load the properties file, so DRIVER is null, so you get the stack trace.
 
Craig Giles
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


thanks for all the help
 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can actually check if the connection object is initialized properly by printing the connection object to console .....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!