关于J2ME显示图片的问题!急啊!
我之前有C++基础,现在刚开始学J2ME。写了一个小程序,显示一个png格式的图片,遇到了一点问题!代码如下:importjava.io.IOException;impo...
我之前有C++基础,现在刚开始学J2ME。写了一个小程序,显示一个png格式的图片,遇到了一点问题!代码如下:
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class TestImage extends Canvas {
Image img;
public TestImage() throws IOException {
try
{
img = Image.createImage("/res/plane.PNG");
}
catch (IOException e)
{
System.out.println("读取图片异常!"+e.getMessage());
}
}
protected void paint(Graphics g) {
try
{
g.drawImage(img, 50, 50, Graphics.LEFT);
}
catch (Exception e)
{
System.out.println("绘制图片异常!"+e.getMessage());
}
}
}
import java.io.IOException;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class TestImageMain extends MIDlet {
TestImage ti = new TestImage();
public TestImageMain() throws IOException {
Display.getDisplay(this).setCurrent(ti);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
已经在res文件夹里面导入了plane.png这个图片,项目根目录里面也有plane.png,可是不知道为什么运行后控制台还是出错:
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\MediaControlSkin
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
读取图片异常!null
绘制图片异常!
Execution completed.
3403941 bytecodes executed
141 thread switches
1668 classes in the system (including system classes)
17799 dynamic objects allocated (532080 bytes)
2 garbage collections (458244 bytes collected)
我把img = Image.createImage("/res/plane.PNG");这一句改成
img = Image.createImage("/plane.PNG");之后,错误信息变成了:
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\MediaControlSkin
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
绘制图片异常!
Execution completed.
3404368 bytecodes executed
213 thread switches
1668 classes in the system (including system classes)
17786 dynamic objects allocated (538996 bytes)
2 garbage collections (458244 bytes collected)
请各位大神帮帮忙,小弟新手,感激不尽! 展开
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class TestImage extends Canvas {
Image img;
public TestImage() throws IOException {
try
{
img = Image.createImage("/res/plane.PNG");
}
catch (IOException e)
{
System.out.println("读取图片异常!"+e.getMessage());
}
}
protected void paint(Graphics g) {
try
{
g.drawImage(img, 50, 50, Graphics.LEFT);
}
catch (Exception e)
{
System.out.println("绘制图片异常!"+e.getMessage());
}
}
}
import java.io.IOException;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class TestImageMain extends MIDlet {
TestImage ti = new TestImage();
public TestImageMain() throws IOException {
Display.getDisplay(this).setCurrent(ti);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
已经在res文件夹里面导入了plane.png这个图片,项目根目录里面也有plane.png,可是不知道为什么运行后控制台还是出错:
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\MediaControlSkin
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
读取图片异常!null
绘制图片异常!
Execution completed.
3403941 bytecodes executed
141 thread switches
1668 classes in the system (including system classes)
17799 dynamic objects allocated (532080 bytes)
2 garbage collections (458244 bytes collected)
我把img = Image.createImage("/res/plane.PNG");这一句改成
img = Image.createImage("/plane.PNG");之后,错误信息变成了:
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\MediaControlSkin
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
绘制图片异常!
Execution completed.
3404368 bytecodes executed
213 thread switches
1668 classes in the system (including system classes)
17786 dynamic objects allocated (538996 bytes)
2 garbage collections (458244 bytes collected)
请各位大神帮帮忙,小弟新手,感激不尽! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询