Button and ImageView not working well together?
<p>This is perhaps a very simple error, but I can't find it! It want to close the application at start if I have the ImageView before the Button in the layout! But not if I have the Button first and then the ImageView!? What could be the reason for this? I have pasted some of the code and hope that could tell what the error is? Preciate the help! Thanks!</p>

<p>Activity:</p>

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

ImageView imageView;

public final static String test ="Hello";

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


    Button btnImageMenu = (Button) findViewById(R.id.btnStartActivity_2);
    imageView = (ImageView) findViewById(R.id.full_image_view);

    registerForContextMenu(imageView);

    // Button to open activity with gridview
    btnImageMenu.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            Intent i = new Intent("com.test.ACTIVITY_2"); // Alternative
            startActivityForResult(i, 1);
        }
    });
}

// Create context menu
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    // TODO Auto-generated method stub
    super.onCreateContextMenu(menu, v, menuInfo);

    menu.setHeaderTitle("Options for this menu"); // Title for the menu
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_1_menu, menu);
}

// Handle selected items from context menu
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    // Open activity with gridview of thumbnails
    case R.id.menu_option_1:
        // Toast.makeText(Activity_1.this, "" + "Menu option 1", Toast.LENGTH_SHORT).show();

        // Activate activity 3 with listview of contacts
        Intent i = new Intent("com.test.ACTIVITY_3"); // Alternative
        startActivityForResult(i, 2);

        return true;

        // Open activity with listview of contacts
    case R.id.menu_option_2:
        Toast.makeText(Activity_1.this, "" + "Menu option 2",
                Toast.LENGTH_SHORT).show();
        return true;

    default:
        return super.onContextItemSelected(item);
    }
}

// Handle return values from different activities
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == 1) {

            String imageId = data.getExtras().getString("imageId");

            Bitmap bitmap = BitmapFactory.decodeFile(imageId);
            imageView.setImageBitmap(bitmap);
        }

        else if(requestCode == 2) {
            String contact1 = data.getExtras().getString("contactName");
            String contact2 = data.getExtras().getString("test");
            Toast.makeText(Activity_1.this, "" + "Value from activity 3: " + contact1 + " " + contact2, Toast.LENGTH_SHORT).show();

        }
    }
}
</code></pre>

<p>}</p>

<p>Layout:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" &gt;

&lt;ImageView
    android:id="@+id/full_image_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" /&gt;

&lt;Button
    android:id="@+id/btnStartActivity_2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/btnStartActivity_2" /&gt;
</code></pre>

<p></p>

<p>Error log:</p>

<pre><code>02-24 20:34:50.945: I/ApplicationPackageManager(13296): cscCountry is not German : NEE
02-24 20:34:50.976: D/AndroidRuntime(13296): Shutting down VM
02-24 20:34:50.984: W/dalvikvm(13296): threadid=1: thread exiting with uncaught exception (group=0x40018578)
02-24 20:34:51.000: E/AndroidRuntime(13296): FATAL EXCEPTION: main
02-24 20:34:51.000: E/AndroidRuntime(13296): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.assignment.two/com.test.assignment.two.Activity_1}: java.lang.ClassCastException: android.widget.ImageView
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.os.Looper.loop(Looper.java:130)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.app.ActivityThread.main(ActivityThread.java:3687)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at java.lang.reflect.Method.invokeNative(Native Method)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at java.lang.reflect.Method.invoke(Method.java:507)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at dalvik.system.NativeStart.main(Native Method)
02-24 20:34:51.000: E/AndroidRuntime(13296): Caused by: java.lang.ClassCastException: android.widget.ImageView
02-24 20:34:51.000: E/AndroidRuntime(13296):    at com.test.assignment.two.Activity_1.onCreate(Activity_1.java:31)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-24 20:34:51.000: E/AndroidRuntime(13296):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-24 20:34:51.000: E/AndroidRuntime(13296):    ... 11 more
</code></pre>
