gpt4 book ai didi

java - 启动嵌入式 Java DB : Getting NullPointerException in getting configuration. 属性

转载 作者:行者123 更新时间:2023-12-02 07:52:11 27 4
gpt4 key购买 nike

美好的一天!

我是 Java DB (Derby) 的新手。我想将其嵌入到我的应用程序中。我找到了这个网站(http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/)并按照说明进行操作。我复制了部分示例代码并进行了编辑以适合我的类(class)。

当我运行该类时,它返回此错误:

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非常感谢您的帮助!预先感谢您。

最佳答案

您在以下位置得到 NULL

dbPropInputStream = RecordBookDAO.class.getResourceAsStream("Configuration.properties");

检查configuration.properties是否存在。

如果您的属性文件与您用来调用“getResourceAsStream("")”的类位于同一目录中,那么您只需要文件的名称,而不需要它的绝对路径。

关于java - 启动嵌入式 Java DB : Getting NullPointerException in getting configuration. 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10102207/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com