我无法弄清楚以下cocos2d代码中的错误

时间:2015-10-16 06:10:16

标签: cocos2d-iphone

// Add Game Status Label

String test="Tap Tiles to Begin";       
CCBitmapFontAtlas statusLabel = CCBitmapFontAtlas.bitmapFontAtlas(test, "bionic.fnt");
statusLabel.setScale(1.3f* generalscalefactor); //scaled
statusLabel.setAnchorPoint(CGPoint.ccp(0,1));
statusLabel.setPosition( CGPoint.ccp( 25* generalscalefactor , screenSize.height - 10* generalscalefactor));
addChild(statusLabel,-2, STATUS_LABEL_TAG);

,错误是

10-16 01:58:50.424: E/AndroidRuntime(3230): FATAL EXCEPTION: main
10-16 01:58:50.424: E/AndroidRuntime(3230): Process: com.example.puzzlegame, PID: 3230
10-16 01:58:50.424: E/AndroidRuntime(3230): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.puzzlegame/com.example.puzzlegame.MainActivity}: java.lang.NullPointerException: lock == null
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.os.Handler.dispatchMessage(Handler.java:102)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.os.Looper.loop(Looper.java:135)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.ActivityThread.main(ActivityThread.java:5254)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at java.lang.reflect.Method.invoke(Native Method)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at java.lang.reflect.Method.invoke(Method.java:372)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
10-16 01:58:50.424: E/AndroidRuntime(3230): Caused by: java.lang.NullPointerException: lock == null
10-16 01:58:50.424: E/AndroidRuntime(3230):     at java.io.Reader.<init>(Reader.java:64)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at java.io.InputStreamReader.<init>(InputStreamReader.java:120)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at java.io.InputStreamReader.<init>(InputStreamReader.java:57)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at org.cocos2d.opengl.CCBitmapFontAtlas$CCBitmapFontConfiguration.parseConfigFile(CCBitmapFontAtlas.java:161)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at org.cocos2d.opengl.CCBitmapFontAtlas$CCBitmapFontConfiguration.<init>(CCBitmapFontAtlas.java:126)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at org.cocos2d.opengl.CCBitmapFontAtlas$CCBitmapFontConfiguration.configuration(CCBitmapFontAtlas.java:119)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at org.cocos2d.opengl.CCBitmapFontAtlas.FNTConfigLoadFile(CCBitmapFontAtlas.java:515)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at org.cocos2d.opengl.CCBitmapFontAtlas.<init>(CCBitmapFontAtlas.java:490)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at org.cocos2d.opengl.CCBitmapFontAtlas.bitmapFontAtlas(CCBitmapFontAtlas.java:485)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at com.example.puzzlegame.GameLayer.<init>(GameLayer.java:38)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at com.example.puzzlegame.GameLayer.scene(GameLayer.java:75)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at com.example.puzzlegame.MainActivity.onCreate(MainActivity.java:34)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.Activity.performCreate(Activity.java:5990)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
10-16 01:58:50.424: E/AndroidRuntime(3230):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)

1 个答案:

答案 0 :(得分:1)

该错误与该行有关 CCBitmapFontAtlas statusLabel = CCBitmapFontAtlas.bitmapFontAtlas(test,“bionic.fnt”);

确保文件位于正确的目录中并且内容正确无误。