0

I'm developing a game on Eclipse. Im using Java language. The game needs to load .tmx files. I don't know if my codes are correct.

    CCSprite bgtitle;
    CGSize winSize = CCDirector.sharedDirector().displaySize();
    protected CCTMXTiledMap tmap;
    protected CCTMXLayer bbackground;

protected MenuLayer() {
        super();

        bgtitle = CCSprite.sprite("titlescreen.png");
        bgtitle.setPosition(CGPoint.ccp(winSize.width / 2.0f, winSize.height / 2.0f));
        bgtitle.setScaleX(winSize.width/bgtitle.getTexture().getWidth());
        bgtitle.setScaleY(winSize.height/bgtitle.getTexture().getHeight());
        addChild(bgtitle,0);

        tmap = CCTMXTiledMap.tiledMap("tutorial1.tmx"); 
            //^ This is where the error occurs

        bbackground = tmap.layerNamed("Background");


        addChild(tmap, 1);
    }

I'm getting this error messages from logcat:

01-19 03:19:45.193: E/AndroidRuntime(1723): FATAL EXCEPTION: main
01-19 03:19:45.193: E/AndroidRuntime(1723): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cronlygames.cocos2d.template/com.patkrisgame.samplegame.SimpleGame}: java.lang.NullPointerException
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1734)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1753)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.app.ActivityThread.access$1500(ActivityThread.java:155)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:999)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.os.Handler.dispatchMessage(Handler.java:130)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.os.Looper.loop(SourceFile:351)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.app.ActivityThread.main(ActivityThread.java:3820)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at java.lang.reflect.Method.invokeNative(Native Method)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at java.lang.reflect.Method.invoke(Method.java:538)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at dalvik.system.NativeStart.main(Native Method)
01-19 03:19:45.193: E/AndroidRuntime(1723): Caused by: java.lang.NullPointerException
01-19 03:19:45.193: E/AndroidRuntime(1723):     at org.cocos2d.layers.CCTMXTiledMap.tilesetForLayer(CCTMXTiledMap.java:227)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at org.cocos2d.layers.CCTMXTiledMap.parseLayer(CCTMXTiledMap.java:206)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at org.cocos2d.layers.CCTMXTiledMap.<init>(CCTMXTiledMap.java:143)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at org.cocos2d.layers.CCTMXTiledMap.tiledMap(CCTMXTiledMap.java:115)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at com.patkrisgame.samplegame.SimpleGame$MenuLayer.<init>(SimpleGame.java:202)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at com.patkrisgame.samplegame.SimpleGame$MenuLayer.scene(SimpleGame.java:218)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at com.patkrisgame.samplegame.SimpleGame.onCreate(SimpleGame.java:90)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
01-19 03:19:45.193: E/AndroidRuntime(1723):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1698)
01-19 03:19:45.193: E/AndroidRuntime(1723):     ... 11 more

The error is nullpointerexception but the tilemap is already in the assets folder. I tried putting it to the other folders but it still didnt work. Any suggestions and examples will be appreciated.

  • from your log, i think you may have placed wrong name for layer.Please check it once.If you want to refer examples, you can get from library itself(org.cocos2d.tests package).check this – Rama Jan 20 '14 at 10:10

1 Answers1

0

you need to copy your picture to the working directory--assets.

orzangleli
  • 178
  • 7