Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 调用超级构造函数时的GroovyCastException_Class_Inheritance_Groovy - Fatal编程技术网

Class 调用超级构造函数时的GroovyCastException

Class 调用超级构造函数时的GroovyCastException,class,inheritance,groovy,Class,Inheritance,Groovy,我有一个抽象Groovy类GameScreen,它在构造函数中接收一些参数: GameScreen(game, background, screenSize) { ... } 然后我从基类派生出一个子类LoadingScreen。在子类的构造函数中,我调用超级构造函数,如下所示: LoadingScreen(game) { super(game, new Color(0.0f, 0.0f, 0.2f, 1.0f), Constants.SCREEN_SIZE) } int count

我有一个抽象Groovy类
GameScreen
,它在构造函数中接收一些参数:

GameScreen(game, background, screenSize)
{ ... }
然后我从基类派生出一个子类
LoadingScreen
。在子类的构造函数中,我调用超级构造函数,如下所示:

LoadingScreen(game)
{
    super(game, new Color(0.0f, 0.0f, 0.2f, 1.0f), Constants.SCREEN_SIZE)
}
int counter = null
game
是一个非空对象时,
new Color()
应该是清晰的,
常量。SCREEN\u SIZE
是另一个非空对象

然而,当我现在运行Groovy应用程序时,我在加载屏幕的超级构造函数调用中遇到以下错误:

Exception in thread "LWJGL Application" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead
问题是:我不知道这个错误意味着什么。此错误消息指的是什么?哪个对象是空的?我检查了调试器,并且
游戏
肯定不是空的

由于我没有更多的想法,我删除了基类
GameScreen
中构造函数的所有参数,并从子构造函数调用其构造函数,然后简单地称为
super()
。然而,我仍然得到完全相同的错误,所以我怀疑是其他原因触发了它


有什么想法吗?

对代码进行了一点重构后,我发现在我的基类
GameScreen
中有一个类变量实例化如下:

LoadingScreen(game)
{
    super(game, new Color(0.0f, 0.0f, 0.2f, 1.0f), Constants.SCREEN_SIZE)
}
int counter = null

null
更改为
-1
后,它现在可以工作了。当然,这是有道理的。但是,此错误消息确实具有误导性,因为它不是指该行,而是指构造函数本身:(

你能发布足够的代码来重现问题吗?我尝试了一些关于你的代码的假设,可以毫无问题地实例化这个超类OK,感谢你要求我提供更多的代码--我正在准备一个简单的示例,发现了问题。我已经更新了我的原始帖子…你可以发布你的更新作为答案。