I have a base class which has a bunch of buttons that are going to be used on all my activities as a general navigation bar.
public abstract class GenericActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
final Button buttonFinder = (Button) findViewById(R.id.buttonNavigationFinder);
buttonFinder.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent IndexActivity = new Intent(GenericActivity.this, Finder.class);
GenericActivity.this.startActivity(IndexActivity);
}
});
final Button buttonIndex = (Button) findViewById(R.id.buttonNavigationIndex);
buttonIndex.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent IndexActivity = new Intent(GenericActivity.this, Index.class);
GenericActivity.this.startActivity(IndexActivity);
}
});
final Button buttonStart = (Button) findViewById(R.id.buttonNavigationStart);
buttonStart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent IndexActivity = new Intent(GenericActivity.this, MainMenu.class);
GenericActivity.this.startActivity(IndexActivity);
}
});
}
}
I then inherit this activity in another activity
public class Index extends GenericActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.index);
}
}
The XML file of the index layout have buttons with the same IDs as the base class. When I start the Index activity my emulator crashes. Help!
EDIT: Stacktrace, but I cant seem to get the whole trace. Logcat shows “… 11 more” at the end
http://pastebin.com/v64RyG2S
Try this:
remove
setContentView(R.layout.main_menu);fromGenericActivity.What
main_menu.xmlhas?and change these methods calls order on
Indexclass: