title: Class cast exception in FrameLayout when am trying to change the order of views in layout xml?
body: <p>Here is my layout file</p>
  
  <pre><code> &lt;FrameLayout
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="3"&gt;
  
      &lt;WebView
          android:id="@+id/document_id"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
     &lt;ProgressBar
          android:id="@+id/load_document_progress"
          android:layout_width="30dp"
          android:layout_gravity="center"
          android:layout_height="30dp"
          android:visibility="invisible"/&gt;
  
      &lt;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"/&gt;
  
  
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>This is working. But when I have to change the order of the elements. I will get <strong>ClassCastException</strong>. Here is my my logcat trace.</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>And here is my <strong>Activity</strong> code </p>
  
  <pre><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);
  }
  </code></pre>
  
  <p>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?</p>