New activity throwing nullpointer

allelsorier

New Member
How do I simply display another xml file? I have created a new activity call \[code\]about.java\[/code\] to do that but it crashed with a \[code\]NullPointerException\[/code\]. Here's my main class calling \[code\]about.class\[/code\]:\[code\]public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 1: Log.d("**MYLOG**", "Refresh clicked .. "); Intent intent = new Intent(this, MainActivity.class); this.startActivity(intent); return true; case 2: //setContentView(R.layout.about); Log.d("**MYLOG**", "About clicked .. "); Intent intent2 = new Intent(this, About.class); this.startActivity(intent2); return true;\[/code\]Here is my about.class\[code\]public class About extends Activity {public About() { Log.d("**MYLOG**", "Inside About.java .."); setContentView(R.layout.about);}}\[/code\]and my about.xml\[code\]<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="bold" android:typeface="sans" android:textSize="18dp" android:text="About page" android:gravity="center"></TextView>\[/code\]Here is my log:\[code\]12-26 14:28:43.560: D/**MYLOG**(1141): Inside About.java ..12-26 14:28:43.560: D/AndroidRuntime(1141): Shutting down VM12-26 14:28:43.560: W/dalvikvm(1141): threadid=1: thread exiting with uncaught exception (group=0x40a13300)12-26 14:28:43.600: E/AndroidRuntime(1141): FATAL EXCEPTION: main12-26 14:28:43.600: E/AndroidRuntime(1141): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{wia.home/wia.home.About}: java.lang.NullPointerException12-26 14:28:43.600: E/AndroidRuntime(1141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)12-26 14:28:43.600: E/AndroidRuntime(1141): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)12-26 14:28:43.600: E/AndroidRuntime(1141): at android.app.ActivityThread.access$600(ActivityThread.java:130)12-26 14:28:43.600: E/AndroidRuntime(1141): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)12-26 14:28:43.600: E/AndroidRuntime(1141): at android.os.Handler.dispatchMessage(Handler.java:99)12-26 14:28:43.600: E/AndroidRuntime(1141): at android.os.Looper.loop(Looper.java:137)12-26 14:28:43.600: E/AndroidRuntime(1141): at android.app.ActivityThread.main(ActivityThread.java:4745)12-26 14:28:43.600: E/AndroidRuntime(1141): at java.lang.reflect.Method.invokeNative(Native Method)12-26 14:28:43.600: E/AndroidRuntime(1141): at java.lang.reflect.Method.invoke(Method.java:511)12-26 14:28:43.600: E/AndroidRuntime(1141): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)12-26 14:28:43.600: E/AndroidRuntime(1141): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)12-26 14:28:43.600: E/AndroidRuntime(1141): at dalvik.system.NativeStart.main(Native Method)12-26 14:28:43.600: E/AndroidRuntime(1141): Caused by: java.lang.NullPointerException12-26 14:28:43.600: E/AndroidRuntime(1141): at android.app.Activity.setContentView(Activity.java:1867)\[/code\]
 
Back
Top