gpt4 book ai didi

android - 当我试图更改布局 xml 中的 View 顺序时,FrameLayout 中的类转换异常?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:44:21 27 4
gpt4 key购买 nike

这是我的布局文件

 <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

这是我的 Activity 代码

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() 中 View 的可见性。请帮助我在这里做错了什么?

最佳答案

当您更改小部件的顺序时。清理您的项目并重新构建它。

在 Eclipse 菜单中,项目 --->清理

关于android - 当我试图更改布局 xml 中的 View 顺序时,FrameLayout 中的类转换异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14022007/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com