app crashes when i change the order of my XML RelativeLayout android

android, android-activity, xml, z-index

Solution

I have seen stuff like this before.

Try running a clean build and then run your app again.

on the window bar go to "Project" -> "clean"

clean all solutions and then it should be all good.

Problem

The title says it all, my app keeps crashing everytime i change the layout view, i need the button to be on the very top and the imageView1 to be at the very bottom, with iv_photo being in between them two. So i try to take my xml button and move it to the bottom, and my app crashes, im not changing the code or anything, all im simply doing is moving code around. heres my code DOESNT CRASH ``` <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".DashboardActivity" > <ImageView android:id="@+id/iv_photo" android:layout_width="125dp" android:layout_height="125dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" /> <Button android:id="@+id/btn_crop" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignLeft="@+id/iv_photo" android:layout_alignTop="@+id/iv_photo" android:text="@string/Nothing" /> <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="105dp" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:scaleType="fitXY" android:src="@drawable/whitestrip" /> </RelativeLayout> ``` DOES CRASH ``` <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".DashboardActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="105dp" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:scaleType="fitXY" android:src="@drawable/whitestrip" /> <ImageView android:id="@+id/iv_photo" android:layout_width="125dp" android:layout_height="125dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" /> <Button android:id="@+id/btn_crop" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignLeft="@+id/iv_photo" android:layout_alignTop="@+id/iv_photo" android:text="@string/Nothing" /> </RelativeLayout> ``` Heres the errors i get in the LogCat ``` 05-01 13:49:15.632: E/AndroidRuntime(32148): FATAL EXCEPTION: main 05-01 13:49:15.632: E/AndroidRuntime(32148): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.atmebeta/com.example.atmebeta.DashboardActivity}: java.lang.ClassCastException: android.widget.ImageView 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.os.Handler.dispatchMessage(Handler.java:99) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.os.Looper.loop(Looper.java:123) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.app.ActivityThread.main(ActivityThread.java:3687) 05-01 13:49:15.632: E/AndroidRuntime(32148): at java.lang.reflect.Method.invokeNative(Native Method) 05-01 13:49:15.632: E/AndroidRuntime(32148): at java.lang.reflect.Method.invoke(Method.java:507) 05-01 13:49:15.632: E/AndroidRuntime(32148): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 05-01 13:49:15.632: E/AndroidRuntime(32148): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 05-01 13:49:15.632: E/AndroidRuntime(32148): at dalvik.system.NativeStart.main(Native Method) 05-01 13:49:15.632: E/AndroidRuntime(32148): Caused by: java.lang.ClassCastException: android.widget.ImageView 05-01 13:49:15.632: E/AndroidRuntime(32148): at com.example.atmebeta.DashboardActivity.onCreate(DashboardActivity.java:106) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-01 13:49:15.632: E/AndroidRuntime(32148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) ```

Original source