得到codeBase的()给出空指针的Java小程序 [英] getCodeBase() gives nullpointer in Java Applet
问题描述
我已经创建了一个小程序来读取服务器上的文件的一些信息。我尝试使用以下code访问文件:
属性设置=新特性();
。settings.load(新网址(getDocumentBase(),的Settings.ini))的OpenStream());
突然,第二行是给我的错误:
显示java.lang.NullPointerException
在java.applet.Applet.getDocumentBase(来源不明)
我的小程序签名和访问它通过我的localhost.Why我不能用getDocumentBase了吗?
顺便说一句,我使用NetBeans Web Start的选项来创建必要的文件(jar文件,HTML,JNLP),然后将其移动到我的IIS的本地服务器。
SOLUTION
我是从罐子中现在载入ini文件:
属性设置=新特性();
网址URL = this.getClass()的getResource(/ myapplet /的Settings.ini)。
settings.load(url.openStream());
SOLUTION
我是从罐子中现在载入ini文件:
属性设置=新特性();
网址URL = this.getClass()的getResource(/ myapplet /的Settings.ini)。
settings.load(url.openStream());
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)
My applet is signed and I access it through my localhost.Why can't I use getDocumentBase anymore?
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.
SOLUTION
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
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());
这篇关于得到codeBase的()给出空指针的Java小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!