| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 493 人关注过本帖
标题:内容简单,但异常多多,帮下忙啊!
取消只看楼主 加入收藏
fanschun
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-10-12
收藏
 问题点数:0 回复次数:0 
内容简单,但异常多多,帮下忙啊!

本人一个程序就是通过按方向健实现一幅图片的移动,图片为28*40像素png格式,程序简单, 可运行时抛出的异常让我郁闷不已,实在是太多了,我也被弄得无可耐何,请帮忙啊!!! import javax.microedition.lcdui.*; import java.io.*;

public class picture extends Canvas{ //定义类Canvas Image img; Display display; int x=getWidth()/2; int y=getHeight()/2; public picture(Display d){ display=d; try{ img=Image.createImage("\10.png"); }catch(IOException e){System.err.println("loading failure");}; } public void paint(Graphics g){ g.setColor(255,255,255); g.fillRect(0,0,getWidth(),getHeight()); g.drawImage(img,x,y,Graphics.HCENTER|Graphics.VCENTER); } public void keyPressed(int keyCode){ switch(getGameAction(keyCode)){ case LEFT:x-=2;repaint();break; case RIGHT:x+=2;repaint();break; case UP:y-=2;repaint();break; case DOWN:y+=2;repaint();break; } } public void start(){ display.setCurrent(this); repaint(); } }

import javax.microedition.lcdui.*; import javax.microedition.midlet.*;

public class p183 extends MIDlet{ Display display; picture mypicture; public p183(){ display=Display.getDisplay(this); mypicture=new picture(display); } public void startApp(){ mypicture.start(); } public void pauseApp(){} public void destroyApp(boolean a){} }

运行时抛出的异常如下: 生成完成 正在通过存储根 DefaultColorPhone 来运行 loading failure java.lang.NullPointerException: at picture.paint(+44) at javax.microedition.lcdui.Canvas.callPaint(+80) at javax.microedition.lcdui.Display.repaint(+77) at javax.microedition.lcdui.Display.registerNewCurrent(+237) at javax.microedition.lcdui.Display.access$400(+6) at javax.microedition.lcdui.Display$DisplayAccessor.foregroundNotify(+46) at javax.microedition.lcdui.Display$DisplayManagerImpl.notifyWantsForeground(+152) at javax.microedition.lcdui.Display$DisplayManagerImpl.access$100(+6) at javax.microedition.lcdui.Display.setCurrentImpl(+115) at javax.microedition.lcdui.Display.setCurrent(+29) at picture.start(+8) at p183.startApp(+7) at javax.microedition.midlet.MIDletProxy.startApp(+7) at com.sun.midp.midlet.Scheduler.schedule(+270) at com.sun.midp.main.Main.runLocalClass(+28) at com.sun.midp.main.Main.main(+116) java.lang.NullPointerException: at picture.paint(+44) at javax.microedition.lcdui.Canvas.callPaint(+80) at javax.microedition.lcdui.Display.repaint(+77) at javax.microedition.lcdui.Display$DisplayAccessor.repaint(+14) at javax.microedition.lcdui.Display$DisplayManagerImpl.repaint(+16) at com.sun.midp.lcdui.DefaultEventHandler.repaintScreenEvent(+24) at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+774) 请大家帮下忙啊,非常感谢!!!

2005-10-13 12:58
快速回复:内容简单,但异常多多,帮下忙啊!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024769 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved