android program crashes when I start a certain activity
I have a main activity and 3 sub activities. I can navigate to 2 of them
fine, when I try to go to 3rd one, my app crashes. here is the code for
starting the activity that crashes:
in = new Intent(this, BarPage.class);
in.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(in);
break;
here is the code for the activity im starting:
public class BarPage extends Activity {
public static Context appContext;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bar_page_lo);
// Show the Up button in the action bar.
setupActionBar();
appContext = getApplicationContext();
TextView tv= (TextView)findViewById(R.id.tv_bar_name);
InputStream ins;
byte[] bytes;
String string;
try {
ins = appContext.getResources().getAssets().open("bar-data.json");
bytes = new byte[ins.available()];
ins.read(bytes);
string = new String(bytes);
JSONObject jsonobj = new JSONObject(string);
tv.setText(jsonobj.getString("name"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
here is the layout for the activity I'm starting:
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".BarPage" >
<TextView
android:id="@+id/tv_bar_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
here is my error:
08-10 21:06:59.922: W/dalvikvm(3941): VFY: unable to resolve static
method 9: Landroid/support/v4/app/NavUtils;.navigateUpFromSameTask
(Landroid/app/Activity;)V
08-10 21:06:59.922: D/dalvikvm(3941): VFY: replacing opcode 0x71 at 0x000c
08-10 21:06:59.973: D/AndroidRuntime(3941): Shutting down VM
08-10 21:06:59.992: W/dalvikvm(3941): threadid=1: thread exiting with
uncaught exception (group=0x40a71930)
08-10 21:07:00.202: E/AndroidRuntime(3941): FATAL EXCEPTION: main
08-10 21:07:00.202: E/AndroidRuntime(3941): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.hawaiibarbook/com.hawaiibarbook.BarPage}:
java.lang.NullPointerException
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.ActivityThread.access$600(ActivityThread.java:141)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.os.Looper.loop(Looper.java:137)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.ActivityThread.main(ActivityThread.java:5041)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
java.lang.reflect.Method.invokeNative(Native Method)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
java.lang.reflect.Method.invoke(Method.java:511)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
dalvik.system.NativeStart.main(Native Method)
08-10 21:07:00.202: E/AndroidRuntime(3941): Caused by:
java.lang.NullPointerException
08-10 21:07:00.202: E/AndroidRuntime(3941): at
com.hawaiibarbook.BarPage.setupActionBar(BarPage.java:59)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
com.hawaiibarbook.BarPage.onCreate(BarPage.java:28)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.Activity.performCreate(Activity.java:5104)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-10 21:07:00.202: E/AndroidRuntime(3941): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-10 21:07:00.202: E/AndroidRuntime(3941): ... 11 more
No comments:
Post a Comment