良い一日!
Java DB (Derby) の使用は初めてです。アプリケーションに組み込みたい。この Web サイト (http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/) を見つけて、指示に従いました。サンプル コードの一部をコピーし、クラスに合わせて編集しました。
クラスを実行すると、次のエラーが返されます。
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)
これは、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;
}
クラスの完全なコードは、http: //dl.dropbox.com/u/34926392/RecordBookDAO.javaで入手できます 。前もって感謝します。