[j2me game] FullCavnas问题
phxyoung
2009-05-18
刚接触j2me, 在书上看到一个j2me的例子,一运行就抛出如下问题,
Running with storage root C:\Documents and Settings\ZW\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.lang.NoClassDefFoundError: myCanvas: com/nokia/mid/ui/FullCanvas at com.sun.midp.midlet.MIDletState.createMIDlet(+29) 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. 3399723 bytecodes executed 18 thread switches 1669 classes in the system (including system classes) 17741 dynamic objects allocated (538584 bytes) 4 garbage collections (462968 bytes collected) 附上源代码,请高手看一下是哪里的问题。 gameStart.java import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class gameStart extends MIDlet{ public static gameStart midlet; public myCanvas mc; public gameStart() { gameStart.midlet=this;//全局入口对象 } public void startApp() { gameStart.midlet.startGame(); } public void pauseApp() {} public void destroyApp(boolean f) {} public void startGame() {mc=null; mc=new myCanvas(); Display.getDisplay(this).setCurrent(mc); } public void exitGame() { this.notifyDestroyed(); } } --------------------------------------------------------------- import javax.microedition.lcdui.*; import java.util.*; import com.nokia.mid.ui.*; public class myCanvas extends FullCanvas { public Image offScreen; public Graphics offg; public int map[][]=new int[8][8]; public Random r1; public Image imCricle,imMine;//pic public int px,py; public int mineNumber=10;//总雷数 public boolean gameOver=false;//游戏是否结束 public boolean gameWin=false;//游戏是否胜利 public myCanvas() { offScreen=Image.createImage(176,208); offg=offScreen.getGraphics(); try{ imCricle=Image.createImage("/cricle.png"); imMine=Image.createImage("/mine.png"); }catch(Exception e){} r1=new Random(); initMap();//初始化雷区 } public void initMap() { for(int n=0;n<mineNumber;n++) {int tmp=Math.abs(r1.nextInt()%64); int row=tmp/8;//行 int col=tmp%8;//列 if(map[row][col]!=20) { map[row][col]=20;//将第row行第col列设成雷 } else {n--;} } } public void drawMap() {offg.setColor(0xFFFFFF); offg.fillRect(0,0,176,208); offg.setColor(0); for(int i=0;i<8;i++) { for(int j=0;j<8;j++) {offg.drawRect(j*20,i*20,20,20); //如果翻开则显示这点周围的雷数 if(map[i][j]!=20&&map[i][j]!=0&&map[i][j]!=10) { offg.drawString(" "+map[i][j],j*20,i*20,0); } else if(map[i][j]==10) { offg.drawString(" 0",j*20,i*20,0); } } } } public void drawCricle() { offg.drawImage(imCricle,px,py,0); } public void drawOver()//绘制游戏结束 { offg.setColor(0xFFFFFF); offg.fillRect(0,0,176,208); offg.setColor(0); offg.drawString("Game Over",30,30,0); for(int i=0;i<8;i++) { for(int j=0;j<8;j++) {if(map[i][j]==20) {offg.drawImage(imMine,j*20,i*20,0);} else {offg.drawRect(j*20,i*20,20,20);} } } } public void drawWin()//绘制游戏胜利 { offg.setColor(0xFFFFFF); offg.fillRect(0,0,176,208); offg.setColor(0); offg.drawString("you Win",30,30,0); } public void paint(Graphics g) {drawMap();//绘制雷区 drawCricle();//绘制选框 if(gameOver){drawOver();} if(gameWin){drawWin();} offg.drawString("new game exit",0,170,0); g.drawImage(offScreen,0,0,0); } public void checkWin() { int count=0;//记录翻开的数量 for(int i=0;i<8;i++) { for(int j=0;j<8;j++) { if(map[i][j]>0) { count++; } } } if(count+this.mineNumber==64) { this.gameWin=true; } } //map[r2][c2]周围的雷数 public int checkNum(int r2,int c2) {int num=0; //左上 if(r2-1>=0&&c2-1>=0)//判断是否有左上 { if(map[r2-1][c2-1]==20){num++;} } //上 if(r2-1>=0) { if(map[r2-1][c2]==20)num++; } //右上 if(r2-1>=0&&c2+1<=7) { if(map[r2-1][c2+1]==20)num++; } //左 if(c2-1>=0) { if(map[r2][c2-1]==20)num++; } //右 if(c2+1<=7) { if(map[r2][c2+1]==20)num++; } //左下 if(r2+1<=7&&c2-1>=0) { if(map[r2+1][c2-1]==20)num++; } //下 if(r2+1<=7) { if(map[r2+1][c2]==20)num++; } //右下 if(r2+1<=7&&c2+1<=7) { if(map[r2+1][c2+1]==20)num++; } return num;//这点周围的雷数 } public void check(int row,int col) { if(map[row][col]==20) {gameOver=true;} else {//判定这点周围的雷数 int k=this.checkNum(row,col); if(k>0)//这点周围有类 { map[row][col]=k;//显示这点周围的雷数 } else//这点周围没有雷 { map[row][col]=10;//翻开这一点 //在判断这点周围的情况 //左上 if(row-1>=0&&col-1>=0) { if(map[row-1][col-1]<10){//判断是否被翻开 check(row-1,col-1); } } //上 if(row-1>=0) { if(map[row-1][col]<10){//判断是否被翻开 check(row-1,col); } } //右上 if(row-1>=0&&col+1<=7) { if(map[row-1][col+1]<10){//判断是否被翻开 check(row-1,col+1); } } //左 if(col-1>=0) { if(map[row][col-1]<10){//判断是否被翻开 check(row,col-1); } } //右 if(col+1<=7) { if(map[row][col+1]<10){//判断是否被翻开 check(row,col+1); } } //左下 if(row+1<=7&&col-1>=0) { if(map[row+1][col-1]<10){//判断是否被翻开 check(row+1,col-1); } } //下 if(row+1<=7) { if(map[row+1][col]<10){//判断是否被翻开 check(row+1,col); } } //右下 if(row+1<=7&&col+1<=7) { if(map[row+1][col+1]<10){//判断是否被翻开 check(row+1,col+1); } } } } } public void keyPressed(int n) {if(n==-6) {gameStart.midlet.startGame();} if(n==-7) {gameStart.midlet.exitGame();} int k=this.getGameAction(n); switch(k) { case FullCanvas.UP: if(py>=20) py-=20; break; case FullCanvas.DOWN: if(py<=20*6){py+=20;} break; case FullCanvas.LEFT: if(px>=20) px-=20; break; case FullCanvas.RIGHT: if(px<=20*6)px+=20; break; case FullCanvas.FIRE: int seleRow=py/20;//当前选框的所在行 int seleCol=px/20;//当前选框的所在列 check(seleRow,seleCol);//游戏翻开地雷的检测 //检测过关 checkWin(); } this.repaint(); this.serviceRepaints(); } } |
|
fonter
2009-05-19
java.lang.NoClassDefFoundError: myCanvas: com/nokia/mid/ui/FullCanvas
此异常为没有打到这个类 |
|
phxyoung
2009-05-20
fonter 写道 java.lang.NoClassDefFoundError: myCanvas: com/nokia/mid/ui/FullCanvas
此异常为没有打到这个类 事实上我已经导入了这个包,Eclipse的代码检查也没有报错 |
|
redduke1202
2009-06-27
com/nokia/mid/ui/FullCanvas
是诺基亚的包 wtk怎么会支持呢? 用这个类的话得在诺基亚的模拟器或真机上才能运行 |
|
jyasa
2009-07-03
你打包的时候得导入NOKIA的包
WTK有个NOKIA包的补丁的。选择那个模拟器打包运行就不会出错了 |