鱼C论坛

 找回密码
 立即注册
查看: 2924|回复: 2

[已解决]Java 问题求助

[复制链接]
发表于 2021-10-18 10:26:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 oooooook 于 2021-10-18 11:04 编辑

屏幕截图 2021-10-18 102128.jpg
这paint方法里边obj[i].draw(g);[里边有i]循环运行没有图
屏幕截图 2021-10-18 102229.jpg
这个paint方法把obj[i].draw(g);里边的i变成具体数字obj[2].draw(g);就有图了
我这是哪里打错了
这个是报错的内容:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at man.Man$DrawMan.paint(Man.java:23)
        at javax.swing.JComponent.paintChildren(JComponent.java:889)
        at javax.swing.JComponent.paint(JComponent.java:1065)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
        at javax.swing.JComponent.paintChildren(JComponent.java:889)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5226)
        at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572)
        at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1265)
        at javax.swing.JComponent.paint(JComponent.java:1042)
        at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
        at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79)
        at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116)
        at java.awt.Container.paint(Container.java:1973)
        at java.awt.Window.paint(Window.java:3912)
        at javax.swing.RepaintManager$4.run(RepaintManager.java:835)
        at javax.swing.RepaintManager$4.run(RepaintManager.java:807)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:807)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:782)
        at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:731)
        at javax.swing.RepaintManager.access$1300(RepaintManager.java:64)
        at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1720)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:702)
        at java.awt.EventQueue$3.run(EventQueue.java:696)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:719)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Process finished with exit code 0
这个是不是因为我的for里边的循环数与数组赋值的数不同
最佳答案
2021-10-19 10:00:43
java.lang.NullPointerException,空指针异常
obj[3]、obj[4]的值为null,没有赋初值
你把循环里的内容改为i<3试试
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-19 10:00:43 | 显示全部楼层    本楼为最佳答案   
java.lang.NullPointerException,空指针异常
obj[3]、obj[4]的值为null,没有赋初值
你把循环里的内容改为i<3试试
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-10-19 10:55:25 | 显示全部楼层
巴巴鲁 发表于 2021-10-19 10:00
java.lang.NullPointerException,空指针异常
obj[3]、obj[4]的值为null,没有赋初值
你把循环里的内容改 ...

太对了,哥
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-22 18:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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