• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.NullPointerException

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


thanks for all the help
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can actually check if the connection object is initialized properly by printing the connection object to console .....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic