Android: StartActivityForResult causes StackOverFlow Error
I have a gridView that displays some icons (in a Main Menu format) - Based on the Icon pressed I need to launch an activity. I am doing this using a switch statement.
It works fine for two of my activities, however when I try to launch a third activity I get a StackOverFlow Error.
StackTrace:
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): Uncaught handler: thread main exiting due to uncaught exception
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): java.lang.StackOverflowError
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.app.Activity.startActivityForResult(Activity.java:2749)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at com.***.NotesMainMenuActivity.startActivity(NotesMainMenuActivity.java:86)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at com.***.NotesMainMenuActivity$1.onItemClick(NotesMainMenuActivity.java:45)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.widget.AdapterVie开发者_运维问答w.performItemClick(AdapterView.java:284)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.os.Handler.handleCallback(Handler.java:587)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.os.Looper.loop(Looper.java:123)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-11 11:32:44.219: ERROR/AndroidRuntime(18842): at dalvik.system.NativeStart.main(Native Method)
StackTrace indicates that the offending lines are: 86 and 45.
Line 45
Line 45 is part of the OnClickListener where I call a method to choose which activity to start:
private void setClickListenter()
{
grid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
startActivity(position); <--- Line 45
}
});
}
Line 86
Line 86 is where I create an intent after to start the new Activity
Intent i;
switch(position)
{
case ITEM_CLICK_NEWNOTE:
i = new Intent(this, NoteEditActivity.class);
startActivityForResult(i, ACTIVITY_CREATE);
break;
case ITEM_CLICK_VIEWNOTES:
i = new Intent(this, NotesListActivity.class);
startActivityForResult(i, VIEW_NOTES);
break;
case ITEM_CLICK_RECYCLED:
Log.w("MainMenuAdapter", "Got into Recycled Switch");
i = new Intent(this, RecycledNotesListActivity.class); <--- Line 86
startActivityForResult(i, RECYCLED_NOTES);
break;
}
The top two parts of the switch statement ITEM_CLICK_NEWNOTE and ITEM_CLICK_VIEWNOTES work correctly - The activity starts as expected. Only ITEM_CLICK_RECYCLED causes an error. Based on throwing some Log lines into the code into RecycledNotesListActivity.java I don't believe any of the code in that runs. It breaks before then.
I'm confused because all three parts of the switch statement are the same, yet two work and one doesn't.
What have I done wrong?
精彩评论