android – 当我试图改变布局xml中的视图顺序时,FrameLayout中的类转换异常?

前端之家收集整理的这篇文章主要介绍了android – 当我试图改变布局xml中的视图顺序时,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>

这很有效.但是当我必须改变元素的顺序时.我会得到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: Unable to start activity
ComponentInfo{com.zoho.showmote/com.zoho.showmote.android.activity.ShowDocuments}:
java.lang.ClassCastException: android.widget.Button cannot be cast to
android.widget.ProgressBar 12-24 18:33:58.131: E/AndroidRuntime(2089):
at
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): at
android.app.ActivityThread.access$600(ActivityThread.java:123) 12-24
18:33:58.131: E/AndroidRuntime(2089): at
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): at
android.os.Looper.loop(Looper.java:137) 12-24 18:33:58.131:
E/AndroidRuntime(2089): at
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): Caused by: java.lang.ClassCastException:
android.widget.Button cannot be cast to 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.ShowDocuments.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): at
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 more

这是我的活动代码

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);
}

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

解决方法

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

在Eclipse菜单中,Project —> Clean

原文链接:https://www.f2er.com/android/309221.html

猜你在找的Android相关文章