0

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();
            }
        }
4
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by jalpesh_007
0

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?

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.