android.widget.ProgressBar无法转换为android.widget.LinearLayout

3

给定条件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".InboxActivity" >

    <!-- refresh button -->

    <Button
        android:id="@+id/button_refresh_inbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:onClick="refreshInbox"
        android:text="@string/refresh_inbox" />

    <LinearLayout
        android:id="@+id/inbox_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button_refresh_inbox" >

        <ProgressBar
            android:id="@+id/inbox_prog_bar"
            style="@android:style/Widget.ProgressBar.Small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <TextView
        android:id="@+id/empty_inbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/inbox_container"
        android:textIsSelectable="false" />

</RelativeLayout>

结果:

当我运行应用程序时,出现错误。

E/AndroidRuntime(930): java.lang.ClassCastException: android.widget.ProgressBar
cannot be cast to android.widget.LinearLayout

有人知道如何修复这个问题吗?

目标:

在加载收件箱时显示进度条,然后使收件箱内容填充线性布局。

背景:

一切都运行良好。我只是认为在加载收件箱时有一个进度条而不是空白屏幕更好。添加进度条导致出现错误。(我真的想在布局文件中指定进度条,而不是通过编程方式)。


1
展示你的活动。 - Ahmad
1
如果你确定你的代码是正确的,那么尝试清理项目。我曾经遇到过同样的问题,清理项目解决了我的问题。 - user2436477
2个回答

10

刷新并清理你的项目。

这与自动生成R引用时出现的一些混乱有关,清理后会创建一个带有正确id引用的新引用。


1
为什么当LinearLayout不是基类时要进行强制转换?
java.lang.Object

↳ android.view.View

↳ android.widget.ProgressBar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接