图像列表J2ME

时间:2013-01-20 11:47:46

标签: java java-me lcdui j2mepolish

嗨我想在j2me中显示带有字符串的图像列表,下面是我的代码

enter image description here

   public ListImage() {
    try {
        for (int i = 0; i < 2; i++)
            img[i] = Image.createImage("/res/flag_" + i + ".png");

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}

在这里,您可以看到图像位于res文件夹中,我正在使用/ res / flag_访问图像但是仍然出现空指针异常错误

  Using Untrusted simulated domain
 Cannot read /res/flag_0.png
java.lang.NullPointerException
 at ListImage.startApp(+12)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
 null
null
null
java.lang.NullPointerException
at ListImage.startApp(+12)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
null

1 个答案:

答案 0 :(得分:2)

J2ME中,res是任何图像,数据等文件的资源目录。默认情况下,它的路径为root (/)。因此不需要在路径/res/MyImage.png中使用它的名称。而是将其称为/MyImage.png

示例

Image img = Image.createImage( "/MyImage.png" );  

请参阅

  1. Developing J2ME applications with EclipseME
  2. J2ME Tutorial: User Interfaces with MIDP 2.0
  3. Where do I put images in J2me application