1

I'm trying to create a splash screen using LWUIT. I want a form to load and display text and an imagefor 5 seconds then continue to the next form. I have a code but fails to show the image. The class and the image are stored together int he same package. Instead, it shows an error.

java.io.IOException

What could be the problem? This is the code

 package tungPackage;

 import com.sun.lwuit.Display;
 import com.sun.lwuit.Form;
 import com.sun.lwuit.Image;
 import com.sun.lwuit.Label;
 import javax.microedition.midlet.MIDlet;


 public class photoMidlet extends MIDlet {

 public void startApp() {
    Display.init(this);
      try {
        Form splashscreen = new Form();

        // Label splashText   = new Label("Baldy");
        Image image        = Image.createImage("/splash.png");
        Label pictureLabel = new Label(image);

        splashscreen.addComponent(pictureLabel);
        splashscreen.show();
    } catch (Exception ex) {

        Form x = new Form("ERROR");

        String y = ex.toString();

       Label g = new Label(y);

       x.addComponent(g);
       x.show();

    }

 }

 public void pauseApp() {
 }

 public void destroyApp(boolean unconditional) {
 }
 }
gnat
  • 6,213
  • 108
  • 53
  • 73
sammyukavi
  • 1,501
  • 2
  • 23
  • 51
  • What is the exception message displayed? – default locale Apr 06 '12 at 07:06
  • its caught then displayed on the another form x as shown in the code. – sammyukavi Apr 06 '12 at 07:08
  • you should specify this message in your question – default locale Apr 06 '12 at 07:09
  • AFAIU [`Image.createImage(path)`](http://lwuit.java.net/javadocs/com/sun/lwuit/Image.html#createImage%28java.lang.String%29) would be expecting the `path` to represent a file path. Try instead [`Image.createImage(InputStream)`](http://lwuit.java.net/javadocs/com/sun/lwuit/Image.html#createImage%28java.io.InputStream%29) with an IS obtained from an URL. – Andrew Thompson Apr 06 '12 at 07:15
  • @ default locale, I've added the exception @Andrew Thompson the file and the code are locted in the same packege. why would I use a URL? – sammyukavi Apr 06 '12 at 07:23
  • 1
    IOException probably means that jvm is not able to find the file "/splash.png". Check if you have such a file. You can also try giving full file path. – Nishan Apr 06 '12 at 09:00
  • 1
    *"why would I use a URL?"* By run-time, classes and other resource are generally bundled into a Jar. It is not possible to access Jar entries by File, but they are available by URL formed from something like `this.getClass().getResource("the.thing");`. – Andrew Thompson Apr 06 '12 at 14:34

1 Answers1

1

Open your JAR file using a ZIP utility (e.g. 7-zip) and look in the root of the file. If splash.png isn't in the root of the jar that's your problem!

Place splash.png so it is in the root of the jar.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65