使用Java 1.7.25(安全设置为最小值,32位,如果有的话),Windows 8,Google Chrome。Applet无法从jar中加载文件
我写了一个Applet,它需要加载一些图像。一切都装在罐子和HTML文件是这样的:
<html>
<body>
<applet code="package.AppletRun.class"
archive="appletJar.jar" width="1100" height="700">
</applet>
</body>
</html>
我尝试使用多种技术的图像加载:
Image image = applet.getImage(applet.getCodeBase());
Image image = getClass().getResource("relative/package/filename");
Image image = getClass().getResource("/absolute/package/filename");
Image image = getClass().getResource("filename"); //same package
Image image = someStrangeThingsICantEvenRemeber();
问题是一切工作正常(我设置为不加载任何图像),但图像只是不想加载,控制台显示javaNullPointerException
。在Eclipse中没有问题,applet查看器不会投诉。我怎样才能加载图像从jar(类文件相同)到我的小程序?
更重要的是applet.getCodeBase()
回报空,我100%肯定,我不是创造JApplet的实例自己。
你应该接受你自己的答案=) – earcam