Using Java 1.7.25(Security set to minimum, 32bit if that matters), Windows 8, Google Chrome.
I wrote an Applet which needs to load some images. Everything is packed in jar and html file looks like this:
<html>
<body>
<applet code="package.AppletRun.class"
archive="appletJar.jar" width="1100" height="700">
</applet>
</body>
</html>
I tried to load images using several techniques:
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();
The problem is everything works fine (I set not to load any images) but images just don't want to load, console shows javaNullPointerException
. In Eclipse there is no problem, applet viewer doesn't complain. How can I load images from jar(same for class files) to my applet?
What's more applet.getCodeBase()
returns null and I'm 100% sure that I'm not creating JApplet instance myself.
Problem is not with code, but in java(or it's security settings). You have to self-sign jar file you are using. Browser will complain with more warning windows but in the end it will let load(find, access?) files using getClass().getResources(...)
. I have no idea what this signing change, but it works.