very easy question, i’m embarrassed to ask but cannot find it out on my own.
In MainActivity.java there is a menu. When user clicks on the menu item, a new window should appear but the app crashes (“the app stopped unexpectedly”) instead.
MainActivity.java part:
case R.id.Menu6:
Intent intentabout = new Intent(this, About.class);
startActivity(intentabout);
break;
The case should be right, as the other menu items are working.
About.java:
public class About extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutxml);
TextView tv1 = (TextView)findViewById(R.id.TextView01);
tv1.setText("Something");
setContentView(tv1);
}
}
aboutxml.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="Something"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
I have included the class in the AndroidManifest.xml:
<activity
android:name=".About"
android:label="@string/app_name">
</activity>
I can’t believe i don’t know this, i have other class in my app and they are working…
You shouldn’t be calling setContentView twice. Remove the second call. That may or may not be your problem, but it needs to go. If that doesn’t fix it, you need to post your error log. If you view it yourself, you’ll probably figure it out pretty easily, but if not, post it here.