简体   繁体   English

Slick2D中的Unknown NullPointerException

[英]Unknown NullPointerException in Slick2D

I am trying to understand the basics of making a game in Slick2D. 我试图了解在Slick2D中制作游戏的基础知识。 I have 4 classes: Main , Entity , Misc (pastebin.com/e5WqF6Ma) and Fish (pastebin.com/ie0ANxxx) 我有4类: MainEntity ,Misc(pastebin.com/e5WqF6Ma)和Fish(pastebin.com/ie0ANxxx)

Whenever I run the code, this is the console log. 每当我运行代码时,这就是控制台日志。

Mon Aug 17 00:15:07 BST 2015 INFO:Slick Build #237
Mon Aug 17 00:15:07 BST 2015 INFO:LWJGL Version: 2.9.3
Mon Aug 17 00:15:07 BST 2015 INFO:OriginalDisplayMode: 1366 x 768 x 32 @60Hz
Mon Aug 17 00:15:07 BST 2015 INFO:TargetDisplayMode: 640 x 480 x 0 @0Hz
Mon Aug 17 00:15:08 BST 2015 INFO:Starting display 640x480
Mon Aug 17 00:15:08 BST 2015 INFO:Use Java PNG Loader = true
Mon Aug 17 00:15:08 BST 2015 INFO:Controllers not available
Exception in thread "main" java.lang.NullPointerException
    at com..prototypes.project_blueberry.util.Misc.addID(Misc.java:24)
    at com..prototypes.project_blueberry.util.Entity.<init>(Entity.java:16)
    at com..prototypes.project_blueberry.entity.Fish.<init>(Fish.java:15)
    at com..prototypes.project_blueberry.Main.init(Main.java:56)
    at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
    at com..prototypes.project_blueberry.Main.main(Main.java:44)

I have taken out some bits off stuff I don't want online, but the majority of stuff is there. 我从网上不需要的东西中取出了一些东西,但是大部分东西在那里。

I have tried to troubleshoot the code, but I just can't figure out what is causing the exception. 我曾尝试对代码进行故障排除,但我无法弄清楚是什么导致了异常。 Any help? 有什么帮助吗? Thanks. 谢谢。

The problem here is that you haven't initialize the integer array in Misc.java class. 这里的问题是您没有在Misc.java类中初始化整数数组。 If you need to store values into a integer array then you have to initialize it with a given size. 如果需要将值存储到整数数组中,则必须使用给定的大小对其进行初始化。

private static int[] ids = new int[10];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM