2014-09-11 114 views
0

當這裏是我的logcat錯誤:Android應用程序強制關閉改變縱向到橫向

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. 

我得到這個每當我轉我的手機從人像到風景。我的/layout/layout-land的佈局只包含一個顯示圖像的視圖,但在縱向上,它可以被捏和放大,並且位於centerInside之間,在橫向上它是fitxy

這裏是我的肖像

<?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> 

而對於我的風景

<?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> 

回答

1

您的imageview的類型正在從potrait變爲橫向模式。 Potrait使用ImageView而景觀使用TouchImageView。因此,您的findViewById()方法在橫向模式下引用了錯誤的視圖對象。嘗試改變你的Java類中的ImageView的對象TouchImageView然後我猜你的potrait模式會崩潰。

+0

有沒有一種方法,我可以只使用imageview的景觀和適合xy和肖像我可以使用touchimageview中心裏面? – user3334111 2014-09-11 02:33:35

1

你有android:id="@+id/aboutview"com.jc.jcpremiere.TouchImageViewImageView兩個類佈局。

android:id必須是唯一的,所以沒有兩個組件可以具有相同的Android ID。只需將其中一個Android ID更改爲其他內容即可解決問題。

另外,對於縱向和橫向模式都有TouchImageViewImageView - 對於每種模式都沒有不同類型的View組件。

相關問題