Hi.

I have a problem with launching my application as applet. The game runs fine as an application.

my applet code:

package net.viped.breakout;

import java.applet.Applet;
import java.awt.GridLayout;

public class GameApplet extends Applet
{
  Core core = new Core();

  public void init() {
    setLayout(new GridLayout());

    add(this.core);
  }

  public void start() {
    core.start();
  }

  public void stop() {
    core.stop();
  }
}

error:

javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(ImageIO.java:1275)
    at net.viped.breakout.ImageLoader.<init>(ImageLoader.java:14)
    at net.viped.breakout.Core.<init>(Core.java:66)
    at net.viped.breakout.GameApplet.<init>(GameApplet.java:8)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:807)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
    at sun.applet.AppletPanel.run(AppletPanel.java:368)
    at java.lang.Thread.run(Thread.java:680)

Code causing error:

        public ImageLoader() {
            try {
                sprites = ImageIO.read(new File("res/Sprites.png"));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

Hi,

I'm assuming that the Java Content Security Policy is not allowing the applet to read the file. ( if you are running the application through appletviewer etc. )

Or do you have the images and applet bundled in a jar file?

i think whenever you are extending Applet class to any other class,
You have to override all the applet life cycle methods in child(inherited) class.

This article has been dead for over six months. Start a new discussion instead.