English 中文(简体)
阅读财产时的“核心”例外
原标题:Null pointer exception while reading properties file
propsdatabase = new Properties();
InputStream dbin = getClass().getResourceAsStream("/properties/database.properties");
propsdatabase.load(dbin);

我正在通过一个名为数据库的财产档案阅读我的数据库链接细节。 具有多个名称的特性。 The Jus below the fundamentalDirectory.

在出口Eclipse时,该法完全有效。

但是,我利用英特尔利J的Maven项目获得杰尔。 它扔下了Ull点号。

dbin的数值为NUL.(也印制和核对)。

我的结论是,这条道路没有被承认读到档案。

现在 这些物品与英特尔利J公司一道被罚款。

虽然含有适当的双倍信息技术,但在Eclipse jar进行出口时并未发现。 插手帮助

最佳回答

<getResourceAsStream正在退回,其原因是:/properties/database.properties文档不属于Maven等类。

将贵重财产夹在<代码>/src/main/resources的账簿下,如果Maven创设了“jar”档案,则将列入<代码>/properties/database.properties中的资源,并停止领取国家不动产许可证。

问题回答

是的,getResourceAsStream无疑将退回。 我怀疑,你的jar档案没有包括档案。 履历:

jar tvf yourfile.jar

检查。 其次,检查了杰尔案的修建步骤。 如果不看到建筑档案,就很难说什么错了,因此,如果你在研究步骤时发现这种信息的话,请回答你的问题。

您的母体建设步骤是否包括jar里的财产档案? 检查所生产的文件。 如果你不了解你如何总是重新命名,在最后添加一个“.zip”。

您可尝试使用该途径读取财产档案,也可读取档案。

Properties properties = new Properties();
FileInputStream input = null;
try {
   input = new FileInputStream(new File(CONFIGURATION_FILE));
   properties.load(input);
}catch(...){...}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签