在尝试更改布局xml中的视图顺序时,FrameLayout中的类强制转换异常?

Din*_*esh 6 android android-layout android-framelayout

这是我的布局文件

 <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3">

    <WebView
        android:id="@+id/document_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

   <ProgressBar
        android:id="@+id/load_document_progress"
        android:layout_width="30dp"
        android:layout_gravity="center"
        android:layout_height="30dp"
        android:visibility="invisible"/>

    <Button
        android:id="@+id/start_btn"
        android:layout_width="90dp"
        android:layout_height="30dp"
        android:text="@string/start_btn_txt"
        android:textStyle="bold"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:visibility="invisible"
        android:onClick="updatePresentationId"
        android:background="@drawable/border_radius"/>



</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这很有效.但是当我必须改变元素的顺序时.我会得到ClassCastException.这是我的logcat跟踪.

12-24 18:33:58.131:E/AndroidRuntime(2089):FATAL EXCEPTION:main 12-24 18:33:58.131:E/AndroidRuntime(2089):java.lang.RuntimeException:无法启动活动ComponentInfo {com. zoho.showmote/com.zoho.showmote.android.activity.ShowDocuments}:java.lang.ClassCastException:android.widget.Button无法强制转换为android.widget.ProgressBar 12-24 18:33:58.131:E/AndroidRuntime( 2089):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)12-24 18:33:58.131:E/AndroidRuntime(2089):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)12 -24 18:33:58.131:E/AndroidRuntime(2089):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)12-24 18:33:58.131:E/AndroidRuntime(2089):在android. app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)12-24 18:33:58.131:E/AndroidRuntime(2089):at android.os.Handler.dispatchMessage(Handler.java:99)12-24 18: 33:58.131:E/AndroidRuntime(2089):在android.os.Looper.loop(Looper.java:137)12 -24 18:33:58.131:E/AndroidRuntime(2089):在android.app.ActivityThread.main(ActivityThread.java:4424)12-24 18:33:58.131:E/AndroidRuntime(2089):at java.lang .reflect.Method.invokeNative(Native Method)12-24 18:33:58.131:E/AndroidRuntime(2089):at java.lang.reflect.Method.invoke(Method.java:511)12-24 18:33: 58.131:E/AndroidRuntime(2089):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)12-24 18:33:58.131:E/AndroidRuntime(2089):at com.android .internal.os.ZygoteInit.main(ZygoteInit.java:551)12-24 18:33:58.131:E/AndroidRuntime(2089):at dalvik.system.NativeStart.main(Native Method)12-24 18:33: 58.131:E/AndroidRuntime(2089):引起:java.lang.ClassCastException:android.widget.Button无法强制转换为android.widget.ProgressBar 12-24 18:33:58.131:E/AndroidRuntime(2089):at com .zoho.showmote.android.activity.ShowDocuments.getAllViews(ShowDocuments.java:50)12-24 18:33:58.131:E/AndroidRuntime(2089):at com.zoho.showmote.android.activity.ShowDocu ments.onCreate(ShowDocuments.java:39)12-24 18:33:58.131:E/AndroidRuntime(2089):at android.app.Activity.performCreate(Activity.java:4465)12-24 18:33:58.131: E/AndroidRuntime(2089):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)12-24 18:33:58.131:E/AndroidRuntime(2089):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java :1920)12-24 18:33:58.131:E/AndroidRuntime(2089):... 11更多

这是我的活动代码

public void getAllViews()
{
    **progressBar=(ProgressBar)findViewById(R.id.load_document_progress);**
    startButton=(Button)findViewById(R.id.start_btn);
    webView=(WebView)findViewById(R.id.document_id);
    userName=(TextView)findViewById(R.id.userNameTv);
    presentationName=(TextView)findViewById(R.id.presentation_name);
}
Run Code Online (Sandbox Code Playgroud)

我在这个方法的第一行得到了错误.我正在改变Asyntask的onPreExecute和onPostExecute()中视图的可见性.请帮助我在这里做错了什么?

TNR*_*TNR 9

当你改变小工具的顺序.清理您的项目并重新构建它.

在Eclipse菜单中,Project ---> Clean