user3334111
user3334111

Reputation: 21

Android Application force closes when changing portrait to landscape

Here's my LogCat error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jc.jcpremiere/com.jc.jcpremiere.activity2}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.os.Bundle instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/aboutview. Make sure other views do not use the same id.

I'm getting this whenever I switch my phone from portrait to landscape. I have the layout for /layout and /layout-land containing only a view to display images, but on portrait, it can be pinched and zoomed and is on centerInside, and in landscape it's fitxy.

Here's my layout for portrait

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rellayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.jc.jcpremiere.TouchImageView
        android:id="@+id/aboutview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:adjustViewBounds="true"
        android:background="@color/White"
        android:scaleType="centerInside" />

</RelativeLayout>

And for my landscape

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativelayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/aboutview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/White"
        android:scaleType="fitXY" />

</RelativeLayout>

Upvotes: 0

Views: 152

Answers (2)

ChuongPham
ChuongPham

Reputation: 4801

You have android:id="@+id/aboutview" for both your com.jc.jcpremiere.TouchImageView and ImageView classes.

android:id must be unique, so no two components can have the same Android ids. Just change one Android id to something else and that should fix the problem.

Also, have either TouchImageView or ImageView for both portrait and landscape modes - not different types of View component for each mode.

Upvotes: 1

Illegal Argument
Illegal Argument

Reputation: 10358

Your imageview's type is changing from potrait to landscape mode. Potrait uses ImageView while landscape uses TouchImageView. So your findViewById() method references to wrong view object in your landscape mode. Try changing the imageView's object to TouchImageView in your java class then I guess your potrait mode will crash.

Upvotes: 1

Related Questions