游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2206|回复: 0

新手看J2ME精解遇到的问题 wxh(ZT)

[复制链接]

1367

主题

1993

帖子

2118

积分

金牌会员

Rank: 6Rank: 6

积分
2118
发表于 2006-8-4 21:33:00 | 显示全部楼层 |阅读模式
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 啊?

以上问题是为新手入门请大家不吝赐教!谢谢!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-25 01:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表