Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class cast exception in FrameLayout when am trying to change the order of views in layout xml?

Here is my layout file

 <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>

This is working. But when I have to change the order of the elements. I will get ClassCastException. Here is my my logcat trace.

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

And here is my Activity code

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

I got the error at 1st line of this method. I am changing the visibilities of views in Asyntask's onPreExecute and onPostExecute(). Please help what I did wrong here?

like image 449
Dinesh Avatar asked Dec 24 '12 13:12

Dinesh


1 Answers

when you the change the order of Widgets. Clean your project and build it again.

In the Eclipse Menu, Project --->Clean

like image 197
TNR Avatar answered Oct 22 '22 13:10

TNR