Good day!
I’m new in using Java DB (Derby). I want to embed it to my application.
I found this website (http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/) and followed the instructions. I copied parts of the sample code and edited to fit my class.
When I run the class, it returns this error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:435)
at java.util.Properties.load0(Properties.java:354)
at java.util.Properties.load(Properties.java:342)
at recordbook.ui.RecordBookDAO.loadDBProperties(RecordBookDAO.java:40)
at recordbook.ui.RecordBookDAO.<init>(RecordBookDAO.java:28)
at recordbook.ui.RecordBook.<init>(RecordBook.java:34)
at recordbook.ui.RecordBookUI.<init>(RecordBookUI.java:23)
at recordbook.ui.RecordBookUI$3.run(RecordBookUI.java:214)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:617)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
BUILD SUCCESSFUL (total time: 3 seconds)
This is the part of the class where it gets the NullPointerException:
private Properties dbProperties = null;
private final String dbName;
public RecordBookDAO(String recordBookName) {
this.dbName = recordBookName;
setDBSystemDir();
dbProperties = loadDBProperties();
String driverName = dbProperties.getProperty("derby.driver");
loadDatabaseDriver(driverName);
createDatabase();
}
private Properties loadDBProperties() {
InputStream dbPropInputStream = null;
dbPropInputStream = RecordBookDAO.class.getResourceAsStream("Configuration.properties");
dbProperties = new Properties();
try
{
dbProperties.load(dbPropInputStream);
}
catch (IOException ex)
{
ex.printStackTrace();
}
return dbProperties;
}
The complete code for the class is available at: http://dl.dropbox.com/u/34926392/RecordBookDAO.java
Your help is much appreciated! Thank you in advance.
You are getting NULL at
Check that configuration.properties exists.
If your properties file is in the same directory as the class you use to call “getResourceAsStream(“”)”, then you just need the name of the file, without the absolute path to it.