6

ランドスケープモードに切り替えると、Android1.5r3カップケーキで次のカスタムビューが例外をスローします。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.opentable/com.opentable.activity.SearchResults}: 
    java.lang.IllegalArgumentException: Wrong state class -- expecting View State

私のコード:

public class TextProgressBar extends LinearLayout {
    public TextProgressBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.text_progress_bar, this, true);
        setGravity(Gravity.CENTER);
    }

    public TextProgressBar(Context context) {
        this(context,null);
    }
}

このビューのXMLはかなり単純です。

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:id="@+id/progress" />

    <TextView
        android:text="Loading..."
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

何が起こっているのか考えてみませんか?

4

2 に答える 2

9

ああ、最初に述べたように、問題を診断するのは困難だったでしょう。

カスタムビュー内でProgressBarという名前が付けられ@+id/progressていたことがわかりましたが、レイアウトでカスタムビューTextProgressBarを使用した場合、TextProgressBarも呼び出したため@+id/progress、同じIDの2つのビューが作成されました。

それらの1つに名前を変更すると、問題が修正されました。

于 2009-08-25T02:43:10.157 に答える
0

私はフラグメントでviewpagerを使用していました。まず、viewpagerの各フラグメントをテストして、実際にエラーが発生した場所を確認しました。最後に、同じ名前のレイアウトのIDを使用していることがわかりました。次に、ビューのIDを変更しました。

于 2019-07-23T13:43:36.720 に答える