Reputation: 1542
I am trying to pass a list of drawables from one activity to another via bundles. I am doing this under the assumption that primitive arrays can only be passed via bundles in android. Not sure if that's true or not but that's not the point. The point is that I am getting a NullPointerException despite my best efforts. Here is my code from Class A (the sender):
private void startSwitcher() {
int[] mThumb = {
R.drawable.lp_image1_thumb, R.drawable.lp_image2_thumb, R.drawable.lp_image3_thumb,
R.drawable.lp_image4_thumb, R.drawable.lp_image5_thumb, R.drawable.lp_image6_thumb,
R.drawable.lp_image7_thumb, R.drawable.lp_image8_thumb, R.drawable.lp_image9_thumb,
R.drawable.lp_image10_thumb};
Bundle b=new Bundle();
b.putIntArray("mThumbSent", mThumb);
Intent startSwitcher = new Intent(A.this, ImageSwitch1.class);
startSwitcher.putExtras(b);
startActivity(startSwitcher);
And here is the code in the receiver:
public class ImageSwitch1 extends Activity{
Bundle b=this.getIntent().getExtras();
int[] mThumb = b.getIntArray("mThumbSent");
Public Void onCreate...(redacted)
}
Upvotes: 0
Views: 786
Reputation: 6376
You need to put the code into onCreate.
Give this a shot:
public class ImageSwitch1 extends Activity {
int[] mThumbs;
public void onCreate(Bundle icicle) {
mThumbs = getIntent().getExtras().getIntArray("mThumbSent");
}
}
Upvotes: 0
Reputation: 4256
move your code inside onCreate. this.getIntent() will always return NPE because unless the activity is created you will not be able to get the intent.
public class ImageSwitch1 extends Activity{
public void onCreate...(redacted)
Bundle b=this.getIntent().getExtras();
int[] mThumb = b.getIntArray("mThumbSent");
}
Upvotes: 2