错误的状态类别-预期Android 1.5中具有自定义视图的视图状态异常 [英] Wrong state class -- expecting View State exception in Android 1.5 with Custom View
问题描述
当我切换到横向模式时,以下自定义视图会在Android 1.5r3纸杯蛋糕中引发异常:
When I switch to landscape mode, the following custom view throws an exception in Android 1.5r3 cupcake:
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非常简单:
The XML for this view is fairly straightforward:
<?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>
有什么想法吗?
推荐答案
啊,如最初所说,该问题将很难诊断.
Ah, the problem would have been difficult to diagnose as originally stated.
事实证明,在我的自定义视图中,我的ProgressBar被命名为@+id/progress
,但是当我在布局中使用自定义视图TextProgressBar时,我也将其称为TextProgressBar @+id/progress
,从而导致两个具有相同ID的视图.
Turns out that inside my custom view my ProgressBar was named @+id/progress
, but when I used the custom view TextProgressBar in my layout I also called the TextProgressBar @+id/progress
, resulting in two views with the same id.
重命名其中一个解决了该问题.
Renaming one of them fixed the problem.
这篇关于错误的状态类别-预期Android 1.5中具有自定义视图的视图状态异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!