Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: StartActivityForResult causes StackOverFlow Error
    primarykey
    data
    text
    <p>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.</p> <p>It works fine for two of my activities, however when I try to launch a third activity I get a StackOverFlow Error. </p> <p><strong>StackTrace:</strong></p> <pre><code>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.AdapterView.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) </code></pre> <p>StackTrace indicates that the offending lines are: 86 and 45.</p> <p><strong>Line 45</strong></p> <p>Line 45 is part of the OnClickListener where I call a method to choose which activity to start: </p> <pre><code>private void setClickListenter() { grid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { startActivity(position); &lt;--- Line 45 } }); } </code></pre> <p><strong>Line 86</strong></p> <p>Line 86 is where I create an intent after to start the new Activity</p> <pre><code> 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); &lt;--- Line 86 startActivityForResult(i, RECYCLED_NOTES); break; } </code></pre> <p>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. </p> <p>I'm confused because all three parts of the switch statement are the same, yet two work and one doesn't. </p> <p>What have I done wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload