关于J2ME的,只是简单的测试,可出问题了,求助,谢谢了
这是源码:jdk是1.6的,wtk是2.5R
package sp_com_midlet;
import java.io.IOException;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class HandleMidlet extends MIDlet implements CommandListener,ItemStateListener {
private Display display;
private Command cmdOk=new Command("Ok",Command.OK,1);
private Command cmdExit=new Command("Exit",Command.EXIT,1);
private Form form=new Form("姻缘生肖匹配查询");
private Image image;
private ChoiceGroup choicegender_m,choicegender_w,choiceshenxiao_m,choiceshenxiao_w;
public HandleMidlet() {
choicegender_m=new ChoiceGroup("请选择你的性别:",ChoiceGroup.POPUP);
choiceshenxiao_m=new ChoiceGroup("请选择你的生肖:",ChoiceGroup.MULTIPLE);
choicegender_w=new ChoiceGroup("请选择她(他)的性别:",ChoiceGroup.POPUP);
choiceshenxiao_w=new ChoiceGroup("请选择她(他)的生肖:",ChoiceGroup.MULTIPLE);
try {
image=Image.createImage("/con.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
choicegender_m.append("男", image);
choicegender_m.append("女", image);
choiceshenxiao_m.append("鼠", image);
choiceshenxiao_m.append("牛", image);
choiceshenxiao_m.append("虎", image);
choiceshenxiao_m.append("兔", image);
choiceshenxiao_m.append("龙", image);
choiceshenxiao_m.append("蛇", image);
choiceshenxiao_m.append("马", image);
choiceshenxiao_m.append("羊", image);
choiceshenxiao_m.append("猴", image);
choiceshenxiao_m.append("鸡", image);
choiceshenxiao_m.append("狗", image);
choiceshenxiao_m.append("猪", image);
choicegender_w.append("男", image);
choicegender_w.append("女", image);
choiceshenxiao_w.append("鼠", image);
choiceshenxiao_w.append("牛", image);
choiceshenxiao_w.append("虎", image);
choiceshenxiao_w.append("兔", image);
choiceshenxiao_w.append("龙", image);
choiceshenxiao_w.append("蛇", image);
choiceshenxiao_w.append("马", image);
choiceshenxiao_w.append("羊", image);
choiceshenxiao_w.append("猴", image);
choiceshenxiao_w.append("鸡", image);
choiceshenxiao_w.append("狗", image);
choiceshenxiao_w.append("猪", image);
form.append(choicegender_m);
form.append(choiceshenxiao_m);
form.append(choicegender_w);
form.append(choiceshenxiao_w);
form.addCommand(cmdOk);
form.addCommand(cmdExit);
form.setCommandListener(this);
display.setCurrent(form);
}
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 {
display.getDisplay(this);
}
public void commandAction(Command c, Displayable d) {
if(c==cmdOk)
{
String txt="正在发送你的请求,请稍等.......";
form.append(txt);
}
else if(c==cmdExit)
{
try {
this.destroyApp(false);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
}
}
public void itemStateChanged(Item arg0) {
// TODO Auto-generated method stub
}
}
这是抛出的异常:
正在通过存储根 C:\Documents and Settings\haibin.qin\j2mewtk\2.5.2\appdb\DefaultColorPhone 来运行
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
java.io.IOException
at javax.microedition.lcdui.ImmutableImage.getImageFromStream(+15)
at javax.microedition.lcdui.ImmutableImage.<init>(+20)
at javax.microedition.lcdui.Image.createImage(+8)
at sp_com_midlet.HandleMidlet.<init>(+110)
at java.lang.Class.runCustomCode(+0)
at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
at com.sun.midp.midlet.Scheduler.schedule(+52)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)
java.lang.NullPointerException
at sp_com_midlet.HandleMidlet.<init>(+599)
at java.lang.Class.runCustomCode(+0)
at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
at com.sun.midp.midlet.Scheduler.schedule(+52)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)
Execution completed.
3405505 bytecodes executed
28 thread switches
1667 classes in the system (including system classes)
17856 dynamic objects allocated (540324 bytes)
3 garbage collections (460608 bytes collected)
[解决办法]
java.io.IOException
at javax.microedition.lcdui.ImmutableImage.getImageFromStream(+15)
at javax.microedition.lcdui.ImmutableImage. <init>(+20)
at javax.microedition.lcdui.Image.createImage(+8)
at sp_com_midlet.HandleMidlet. <init>(+110)
IO出异常了,在你的程序HandleMidlet第110行,你看一看,是不是那个图片的路径有误?
image=Image.createImage("/con.png");
是不是这句,应该是icon.png吧,你写成了con.png????
[解决办法]
就是图片路径的问题了
楼主确定图片名是 con.png,大小写没错?直接放在res或src目录下么?