Reputation: 1169
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
Upvotes: 1
Views: 1838
Reputation: 72563
Remove the abstract modifier. You can't instantiate abstract classes in java.
Upvotes: 4