错误的州级 - 期望使用自定义视图在Android 1.5中查看状态异常

emm*_*mby 6 android android-view

当我切换到横向模式时,以下自定义视图会在Android 1.5r3蛋糕中引发异常:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.opentable/com.opentable.activity.SearchResults}: 
    java.lang.IllegalArgumentException: Wrong state class -- expecting View State
Run Code Online (Sandbox Code Playgroud)

此视图的XML非常简单:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么想法可能会发生什么?

emm*_*mby 8

啊,问题很难像最初所说的那样被诊断出来.

事实证明,在我的自定义视图中我的ProgressBar被命名@+id/progress,但是当我在我的布局中使用自定义视图TextProgressBar时,我也调用了TextProgressBar @+id/progress,导致两个视图具有相同的id.

重命名其中一个修复了问题.