Sunday, 27 March 2016

XML : Unfortunately, App has stopped on physical device when making changes to .xml in layout-land file in Android

In chapter 3 of Big Nerd Ranch guide, they explain how to differently layout the default and landscape views. But when I create an Android Resource Directory with Landscape orientation and then copy the same .xml from the default layout into the /layout-land and make changes into the latter, the app crashes on my physical device when I rotate to landscape mode.

If I don't change anything in the copied .xml inside the /layout-land file, it runs absolutely fine when rotated.

activity.xml

  <?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:gravity="center"      android:orientation="vertical"      >        <TextView          android:id="@+id/question_text_view"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:padding="24dp" />        <LinearLayout          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:orientation="horizontal">            <Button              android:id="@+id/true_button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="@string/true_button"/>            <Button              android:id="@+id/false_button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="@string/false_button"/>        </LinearLayout>        <LinearLayout          android:layout_width="wrap_content"          android:layout_height="wrap_content"          >            <Button              android:id="@+id/prev_button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="@string/prev_button"/>            <Button              android:id="@+id/next_button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="@string/next_button"/>      </LinearLayout>        </LinearLayout>    

/layout-land/activity.xml

  <?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:gravity="center"      android:orientation="vertical"      >        <TextView          android:id="@+id/question_text_view"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:padding="24dp" />        <LinearLayout          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:orientation="horizontal">            <Button              android:id="@+id/true_button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="@string/true_button"/>            <Button              android:id="@+id/false_button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="@string/false_button"/>        </LinearLayout>        <LinearLayout          android:layout_width="wrap_content"          android:layout_height="wrap_content"          >            <Button              android:id="@+id/prev_button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="@string/prev_button"/>        </LinearLayout>        </LinearLayout>    

Cannot figure out what is the problem. Please help

No comments:

Post a Comment