I tried numerous times to make the app from the MyFirstApp Tutorial on developers.android (https://developer.android.com/training/basics/firstapp/index.html) work. I\'m test
your problem is here (DisplayMessageActivity
):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
you are trying to add the Fragment
to R.id.container
which is not part of the Activity'
s view hierarchy, since the only thing that it contains is a TextView