|
|
1. 刚配好Eclipse3.2便收到了定购的J2ME精解,看到第二章,用第一个例子代码遇到如下错误:
Running with storage root MediaControlSkin
Running with locale: Chinese_People's Republic of China.936
java.lang.IllegalAccessException
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(+116)
Execution completed.
880949 bytecodes executed
4 thread switches
892 classes in the system (including system classes)
4448 dynamic objects allocated (120112 bytes)
2 garbage collections (103844 bytes collected)
源代码 :
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
class TurboMidlet extends MIDlet implements CommandListener{
private Display display = null;
private Form mainForm = null;
public static final Command exitCommand = new Command("退出",Command.OK, 1);
public void startApp() {
if(display == null){
display = Display.getDisplay(this);
}
mainForm = new Form("TurboMIDlet");
Image img = getImage("logo_8.png");
mainForm.append(img);
String text = "";
try{
text = getText("wel.txt");
}catch(IOException ex){
text = "读取文本出错";
}
mainForm.append("\n"+text);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
display.setCurrent(mainForm);
}
private Image getImage(String name){
Image img = null;
try{
//读取images目录下的图片
img = Image.createImage("/images/"+name);
}catch(IOException ex){
ex.printStackTrace();
}
return img;
}
private String getText(String name) throws IOException{
//将资源文件,例如图片和文本,与java流关联的最好方法
InputStream is = getClass().getResourceAsStream("/text/"+name);
if(is != null){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int ch = 0;
while((ch = is.read()) != -1){
baos.write(ch);
}
byte[] text = baos.toByteArray();
baos.close();
//由于包含中文,所以编码转换为UTF-8
return new String(text,"UTF-8");
}else{
return null;
}
}
public void pauseApp() {
//在本例中不做任何处理
}
public void destroyApp(boolean unconditional) {
//在本例中不做任何处理
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == exitCommand){
destroyApp(false);
notifyDestroyed();
}
}
}
是不是我的环境还是什么没搞好啊?不过我的Eclipse 试跑过J2ME的HelloWorld没问题。这个异常的具体含义是什么?大家有像J2SE样的帮助文档吗?请大家多指点!
2.关于Eclipse3.2的使用:我在Eclipse里面Close Project后不知道如何再次打开Project,目前重新打开的只是个 .java文件,还有我想请问下Eclipse有没有集成Tomcat 啊?
以上问题是为新手入门请大家不吝赐教!谢谢!
|
|