How to open an activity after clicking on a Listview that is in Fragment, I am using:
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
OnItemClickListener listener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent intent = new Intent(getActivity(), NovaActivity.class);
startActivity(intent);
}
};
getListView().setOnItemClickListener(listener);
}
but the application stops after clicking. Please if anyone knows how to solve this I appreciate it.
LogCat:
07-01 16:06:32.979: V/21st Polling:(408): clicked 07-01 16:06:36.489: V/21st Polling:(408): clicked 07-01 16:06:39.789: D/AndroidRuntime(408): Shutting down VM 07-01 16:06:39.789: W/dalvikvm(408): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 07-01 16:06:39.849: E/AndroidRuntime(408): FATAL EXCEPTION: main 07-01 16:06:39.849: E/AndroidRuntime(408): java.lang.RuntimeException: Unable to pause activity {com.example.appsherlok/com.example.appsherlok.MainActivity}: java.lang.NullPointerException 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3348) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3305) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3288) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.ActivityThread.access$2500(ActivityThread.java:125) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.os.Handler.dispatchMessage(Handler.java:99) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.os.Looper.loop(Looper.java:123) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-01 16:06:39.849: E/AndroidRuntime(408): at java.lang.reflect.Method.invokeNative(Native Method) 07-01 16:06:39.849: E/AndroidRuntime(408): at java.lang.reflect.Method.invoke(Method.java:521) 07-01 16:06:39.849: E/AndroidRuntime(408): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-01 16:06:39.849: E/AndroidRuntime(408): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-01 16:06:39.849: E/AndroidRuntime(408): at dalvik.system.NativeStart.main(Native Method) 07-01 16:06:39.849: E/AndroidRuntime(408): Caused by: java.lang.NullPointerException 07-01 16:06:39.849: E/AndroidRuntime(408): at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481) 07-01 16:06:39.849: E/AndroidRuntime(408): at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:126) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.Activity.performSaveInstanceState(Activity.java:1036) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1180) 07-01 16:06:39.849: E/AndroidRuntime(408): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3330) 07-01 16:06:39.849: E/AndroidRuntime(408): ... 12 more
Friends, a detail! the app has 3 tabs, that listview is in the first. When I open the app it presents the list, I click, and it works right. But when I go to another tab and go back to the list, I click and the error happens.