4

I created new class and added scene in cocos2d-android but in main class getting this error in class name Cannot instantiate the type Trr where Trr is the name of the class. by googling i found the error was due to Trr was abstract class and directly cannot instantiate. can anybody help me in this?

here's the whole code

**public abstract class Trr extends CCLayer{

public static CCScene scene()
{
    CCScene scene = CCScene.node();
    CCLayer layer = new GameL();
    scene.addChild(layer);  
    return scene;     
}

    CCTextureAtlas atlas;

    static final int kTagNode = 1;
    static final int kTagGrossini = 2;

    public void Trr() {
        CGSize s = CCDirector.sharedDirector().winSize();

        CCLabel label = CCLabel.makeLabel(title(), "DroidSans", 18);
        label.setPosition(s.width / 2, s.height - 30);
        addChild(label, 1);

        CCMenuItemImage item1 = CCMenuItemImage.item("b1.png", "b2.png", this, "backCallback");
        CCMenuItemImage item2 = CCMenuItemImage.item("r1.png", "r2.png", this, "restartCallback");
        CCMenuItemImage item3 = CCMenuItemImage.item("f1.png", "f2.png", this, "nextCallback");

        CCMenu menu = CCMenu.menu(item1, item2, item3);
        menu.setPosition(0, 0);
        item1.setPosition(s.width / 2 - 100, 30);
        item2.setPosition(s.width / 2, 30);
        item3.setPosition(s.width / 2 + 100, 30);
        addChild(menu, 1);
    }

    public abstract String title();
}

**

MainActivity- 2nd line at Trr where i'm getting error.

CCScene scene = CCScene.node();
    scene.addChild(new Trr(), -1); 
    CCDirector.sharedDirector().runWithScene(scene);
James Webster
  • 31,873
  • 11
  • 70
  • 114
DD.
  • 973
  • 2
  • 10
  • 32
  • 4
    why is Trr abstract ? you cannot create an instance of an abstract class – giorashc Jul 08 '13 at 11:57
  • 1
    make it not abstract, fixed – CodeSmile Jul 08 '13 at 20:19
  • hey @LearnCocos2D i'm ur great fan, your works fantastic, why u always write blogs and books on cocos2d-iphone? why not for cocos2d-android so that it will b useful for many peoples here. – DD. Jul 12 '13 at 08:00
  • i don't develop for android, and even then cocos2d-x would be the far more popular choice (personally for cross platform I wouldn't use cocos at all) – CodeSmile Jul 20 '13 at 22:16

1 Answers1

0

You cannot create an instance of an abstract class. To fix, you can just remove the abstract modifier and everything should work fine.

Septic Overflow
  • 135
  • 1
  • 4