Java – Type class names cannot be instantiated in cocos2d

Type class names cannot be instantiated in cocos2d… here is a solution to the problem.

Type class names cannot be instantiated in cocos2d

I created a new class in

cocos2d-android and added a scene, but in the main class, I get this error in the class name Cannot instantiate the type trr, where trr is the name of the class.
Through a Google search I found that the error is due to the fact that trr is an abstract class and cannot be instantiated directly. Can someone help me?

Here is the complete 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();
}

**

An error occurred on line 2 of MainActivity- trr.

CCScene scene = CCScene.node();
    scene.addChild(new Trr(), -1); 
    CCDirector.sharedDirector().runWithScene(scene);

Solution

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

Related Problems and Solutions