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

これを修正する方法を知っている人はいますか?

目的:

受信トレイの読み込み中に表示するプログレス バーを取得します。次に、受信トレイのコンテンツで線形レイアウトを埋めます。

背景:

すべてが正常に機能しています。受信トレイの読み込み中に空白の画面ではなく、進行状況バーを表示する方がよいと思いました. プログレスバーを追加するとエラーが発生しました。(プログラムではなく、レイアウトファイルでプログレスバーを指定したいのですが)。

4

2 に答える 2

9

更新してプロジェクト > 両方のプロジェクトを消去します。

これは、R 参照を自動生成するときに行われるいくつかの混乱に関連しています。クリーニングすると、正しい ID 参照を持つ新しい参照が作成されます。

于 2013-06-25T16:30:14.187 に答える
1

基本クラスではないのに、なぜ LinearLayout にキャストするのでしょうか?

java.lang.Object

↳ android.view.View

↳ android.widget.ProgressBar
于 2013-04-14T16:14:20.870 に答える