gpt4 book ai didi

android - 错误的状态类——在带有自定义 View 的 Android 1.5 中期望 View 状态异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:48:57 25 4
gpt4 key购买 nike

当我切换到横向模式时,以下自定义 View 在 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);
}
}

此 View 的 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>

知道会发生什么吗?

最佳答案

啊,这个问题很难像最初所说的那样诊断。

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

重命名其中之一解决了问题。

关于android - 错误的状态类——在带有自定义 View 的 Android 1.5 中期望 View 状态异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1325576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com