getCodeBase() 在 Java Applet 中给出空指针 [英] getCodeBase() gives nullpointer in Java Applet
问题描述
我创建了一个小程序来从服务器上的文件中读取一些信息.我尝试使用以下代码访问该文件:
I have created an applet to read some info from a file on the server. I try to access the file using the following code:
Properties Settings = new Properties();
settings.load(new URL(getDocumentBase(), "settings.ini")).openStream());
突然,第二行给了我错误:
All of a sudden, the second line is giving me the error:
java.lang.NullPointerException
at java.applet.Applet.getDocumentBase(Unknown Source)
我的小程序已签名,我可以通过我的本地主机访问它.为什么我不能再使用 getDocumentBase?
My applet is signed and I access it through my localhost.Why can't I use getDocumentBase anymore?
顺便说一句,我正在使用 Netbeans Web Start 选项来创建必要的文件(jar、html、jnlp),然后将它们移动到我的 IIS 本地服务器.
Btw, I am using Netbeans Web Start option to create the necessary files (jars, html, jnlp) and then move them to my IIS local server.
解决方案
我现在正在从 jar 中加载 ini 文件:
I'm loading the ini file from within the jar now:
Properties Settings = new Properties();
URL url = this.getClass().getResource("/myapplet/settings.ini");
settings.load(url.openStream());
推荐答案
SOLUTION
我现在正在从 jar 中加载 ini 文件:
I'm loading the ini file from within the jar now:
Properties Settings = new Properties();
URL url = this.getClass().getResource("/myapplet/settings.ini");
settings.load(url.openStream());
这篇关于getCodeBase() 在 Java Applet 中给出空指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!