1

I'm new to Java and Android. I'm trying to extend the Button Class and add more functionality to it for my game. I get an error when I am attempting to initialize the buttons (before runtime, while editing the code in Eclipse) that says "Cannot instantiate the type TTTButton." Can someone please help me figure out what I'm doing wrong here? I've overloaded C++ functions before, so I know(or think) I'm on the right track.

Code:

package com.example.tictactoe;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.*;
import java.lang.String;

public class TicTacToe_2P extends Activity {

    //CONSTANTS
    final int MAXBUTTONS = 9;
    final String tileID = "tile";
    //variables
    TTTButton tile[] = new TTTButton [MAXBUTTONS];

    @Override
    protected void onCreate(Bundle savedInstanceState) {//Start OnCreate
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tic_tac_toe_2_p);
        for(int i = 0; i < MAXBUTTONS; i++){//Initialize each button
            tile[i] = new TTTButton(this);  
        }

        }//End OnCreate
    }

abstract class TTTButton extends Button{//Start TTTButton Class

    //public data
    public boolean isOn = false;
    public int player = 0;

    public TTTButton(Context context) {
        super(context);
        isOn = false;
        player = 0;
    }
}//End TTTButton Class

1 Answer 1

4

Remove the abstract modifier. You can't instantiate abstract classes in java.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.