android indexoutofboundsexception passing bundle through intent
I have stumbl开发者_开发技巧ed upon an issue I can't figure out right now. I get an index out of bounds exception when I pass a bundle to a new activity in intent extras.
I use the following code:
Intent intent = new intent(this, statelistactivity.class);
Bundle bundle = new bundle();
Bundle.putInt("id", _id);
Bundle.putString("name", _name);
Intent.putExtras(bundle);
startactivity(intent);
In the receiving activity I use:
String name = getIntent().getString("name);
Following the same principle for the int.
However my code never gets here because of an outofboundsexception
. What could cause this?
You are not trying to get your string from bundle in which you have put your strings. You should try getting first bundle and from that bundle get all variables-
Bundle b = getIntent().getExtras();
String name = b.getString("name");
I found the solution myself. It was completely diferent from what i suspected.
I have a loop running somewhere for a completely different part of the app. But in the program. The error resided there. Deep down the source, it was in fact an arraylist causing it. Thanks for your time and replies.
精彩评论