2013-04-14 84 views
3

GIVENandroid.widget.ProgressBar不能轉換爲android.widget.LinearLayout

<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

如果您確定您的代碼是正確的,那麼請嘗試清理項目。我遇到同樣的問題,它解決了我的問題。 – 2013-06-14 05:52:11

回答

1

爲什麼要在LinearLayout不是基類時投射?

java.lang.Object 

↳ android.view.View 

↳ android.widget.ProgressBar 
9

刷新和項目>清理你的項目。

這與自動生成R引用時完成的一些混亂有關,清理時會使用正確的id引用創建一個新引用。

相關問題