2014-09-11 117 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组件。

相关问题