Android crashes after running onActivityResult
<p>Hi I'm trying to make a program that will change a picture from class A by picking pictures an grid view image gallery. My grid view class is the same one found on the android main site. I'm changing the imageView buttons by just changing the image resource by using the setImageResource() method.</p>

<p>Now all of my code runs just fine up to the point in the onActivityResult() where the image's resource is being changed, then my program would just crash. I'm not sure what is making my program crash. I know that my code should change the image without problem and that it's reading in the right images to change the original ImageView Button with. Oh and I'm initializing the ImaveView outside of everything so that I can use it in both the onCreate and onActivityResult. Otherwise it wil be outside of the scope of one of those methods. Can someone help me?</p>

<p>This is the code that I'm using.</p>

<pre><code>public class A extends Activity{

private final int Change_Image = 7;
private int Replace_Image = 7;
ImageView spriteImg = null;

    @Override
     public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.objecteditscreen);


   spriteImg = (ImageView) findViewById(R.id.objectSpriteImageBox);
    spriteImg.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(), com.mobilegamelab.ImagesGridView.class);
        startActivityForResult(intent, Change_Image);
    }

});
    }
 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    switch(requestCode)
    {
        case Change_Image:

            if(resultCode== RESULT_OK)
            {
            int result = data.getIntExtra("newPicture", 0);
            Replace_Image = result;

                if (Replace_Image == 0)
                {
                    spriteImg.setImageResource(R.drawable.sample_2);
                }
                else if (Replace_Image == 1)
                {
                    spriteImg.setImageResource(R.drawable.sample_3);
                }
                else if (Replace_Image == 2)
                {
                    spriteImg.setImageResource(R.drawable.sample_4);
                }
                else if (Replace_Image == 3)
                {
                    spriteImg.setImageResource(R.drawable.sample_5);
                }
                else if (Replace_Image == 4)
                {
                    spriteImg.setImageResource(R.drawable.sample_6);
                }
                else if (Replace_Image == 5)
                {
                    spriteImg.setImageResource(R.drawable.sample_7);
                }
                else if (Replace_Image == 6)
                {
                    spriteImg.setImageResource(R.drawable.sample8);
                }

            }
            break;
    }
}
</code></pre>

<p>This is my gridview class</p>

<pre><code>public class ImagesGridView extends Activity {
/** Called when the activity is first created. */

Intent sentIntent;
static int picLocation;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gridview);


    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));

    sentIntent = getIntent();

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
            picLocation = position;
            Intent response = new Intent();
            response.putExtra("newPicture", picLocation);
            setResult(RESULT_OK, response);
            finish();

        }
    });
}
}
</code></pre>
