我写了一个java小程序,俄罗斯方块,为什么运行时会循环出现下面的异常,画面总不能完全显示, 30
Exceptioninthread"AWT-EventQueue-0"java.lang.NullPointerExceptionatplayPane.paintComp...
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at playPane.paintComponent(playPane.java:143)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5131)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1491)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1422)
at javax.swing.RepaintManager.paint(RepaintManager.java:1225)
at javax.swing.JComponent.paint(JComponent.java:1015)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1778)
at java.awt.Window.paint(Window.java:3390)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:797)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:694)
at javax.swing.RepaintManager.access$700(RepaintManager.java:41)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1636)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
程序有时能正常运行(很少) 有时显示画面不完整 只显示一部分 展开
at playPane.paintComponent(playPane.java:143)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5131)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1491)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1422)
at javax.swing.RepaintManager.paint(RepaintManager.java:1225)
at javax.swing.JComponent.paint(JComponent.java:1015)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1778)
at java.awt.Window.paint(Window.java:3390)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:797)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:694)
at javax.swing.RepaintManager.access$700(RepaintManager.java:41)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1636)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
程序有时能正常运行(很少) 有时显示画面不完整 只显示一部分 展开
5个回答
展开全部
at playPane.paintComponent(playPane.java:143)
空指针了,debug调试一下,就能找到问题了,你的程序没有粘出来,只能给个建议,你自己试一下
空指针了,debug调试一下,就能找到问题了,你的程序没有粘出来,只能给个建议,你自己试一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
at playPane.paintComponent(playPane.java:143)
这个地方可能有个某个与之相关的对象没有new就直接用了。。。你再仔细检查一下
这个地方可能有个某个与之相关的对象没有new就直接用了。。。你再仔细检查一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
playPane 这个类的143行附近贴出来看看
应该是调用paint()这个方法时候给进去了null 的对象
应该是调用paint()这个方法时候给进去了null 的对象
更多追问追答
追问
for(int i=0;i<4;i++)
{
g.draw3DRect((int)(this.downBlock.getPoint(i).getX()),(int)(this.downBlock.getPoint(i).getY()),BlockUI.w,BlockUI.h,true);
g.fill3DRect((int)(this.downBlock.getPoint(i).getX()),(int)(this.downBlock.getPoint(i).getY()),BlockUI.w,BlockUI.h,true);
}
这里应该没有null 的啊 我检查了过
追答
循环出现的话很可能是你这两个方法里有问题,导致每次代的时候都会有异常。可以贴出来这两个方法的代码看看;可以在代码里加入system.out.print这方法看看是在哪里扔出来的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询