Android cocos2d添加子节点抛出空指针异常

发布于 2024-12-18 05:54:05 字数 1590 浏览 2 评论 0原文

我对 cocos2d 非常陌生。我正在使用 cocos2d 在 android 中开发一个应用程序。其中,

public class BaseLayer extends CCLayer {

ChildLayer cl = new ChildLayer();
this.addChild(cl); ------------------------------>
}

public class ChildLayer extends CCLayer {

public ChildLayer() {
CCLayer.node();
}
.
.
}

箭头线抛出空指针异常。 错误日志如下..

E/AndroidRuntime(982): FATAL EXCEPTION: GLThread 8
11-26 12:50:33.364: E/AndroidRuntime(982): java.lang.NullPointerException
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCSprite.draw(CCSprite.java:871)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:674)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:680)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:680)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:680)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCDirector.drawCCScene(CCDirector.java:683)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCDirector.onDrawFrame(CCDirector.java:651)
11-26 12:50:33.364: E/AndroidRuntime(982): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
11-26 12:50:33.364: E/AndroidRuntime(982): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
11-26 12:50:34.023: E/libEGL(982): call to OpenGL ES API with no current context (logged once per thread)

我不知道如何解决这个问题..我不知道为什么会发生这种情况..因为我对Cocos2d不太熟悉..请帮我解决这个问题。有人请帮助我..

I am very much new to cocos2d.. I am developing an application in android using cocos2d.. In that,

public class BaseLayer extends CCLayer {

ChildLayer cl = new ChildLayer();
this.addChild(cl); ------------------------------>
}

public class ChildLayer extends CCLayer {

public ChildLayer() {
CCLayer.node();
}
.
.
}

In this, arrowed line throws the Null pointer exception..
Error Log is below..

E/AndroidRuntime(982): FATAL EXCEPTION: GLThread 8
11-26 12:50:33.364: E/AndroidRuntime(982): java.lang.NullPointerException
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCSprite.draw(CCSprite.java:871)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:674)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:680)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:680)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCNode.visit(CCNode.java:680)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCDirector.drawCCScene(CCDirector.java:683)
11-26 12:50:33.364: E/AndroidRuntime(982): at org.cocos2d.nodes.CCDirector.onDrawFrame(CCDirector.java:651)
11-26 12:50:33.364: E/AndroidRuntime(982): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
11-26 12:50:33.364: E/AndroidRuntime(982): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
11-26 12:50:34.023: E/libEGL(982): call to OpenGL ES API with no current context (logged once per thread)

I dont know how to resolve this issue.. I dont know why this occurs.. Since I am not much familiar with Cocos2d.. Please help me to resolve this issue. Somebody please help me..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2024-12-25 05:54:05

这已经解决了..在构造函数中,我调用了超类构造函数,例如CCLayer.node()而不是super()
我改变了,问题就解决了..

This is solved.. In constructor,I have called the super class constructor like CCLayer.node() instead of super()
I changed that and the problem is solved..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文