ClasscastException for viewstub
<p>I am trying to typecast a ViewStub to another class type, but while running the .apk file,when i click for the new screen, the emulator is throwing exception.</p>

<p>The DDMS LogCat has the below exceptions</p>

<pre><code>**06-29 17:21:40.354: ERROR/AndroidRuntime(297): **java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.locive/com.android.locive.ui.ComposeMessageActivity}: java.lang.ClassCastException: android.widget.FrameLayout****
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.os.Looper.loop(Looper.java:123)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at java.lang.reflect.Method.invokeNative(Native Method)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at java.lang.reflect.Method.invoke(Method.java:521)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at dalvik.system.NativeStart.main(Native Method)
**06-29 17:21:40.354: ERROR/AndroidRuntime(297): Caused by: java.lang.ClassCastException: android.widget.FrameLayout
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at com.android.locive.ui.ComposeMessageActivity.initRecipientsEditor(ComposeMessageActivity.java:1607)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at com.android.locive.ui.ComposeMessageActivity.initialize(ComposeMessageActivity.java:1777)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at com.android.locive.ui.ComposeMessageActivity.onCreate(ComposeMessageActivity.java:1690)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-29 17:21:40.354: ERROR/AndroidRuntime(297):     ... 11 more
06-29 17:21:40.443: WARN/ActivityManager(59):   Force finishing activity com.android.locive/.ui.ComposeMessageActivity
06-29 17:21:40.453: WARN/ActivityManager(59):   Force finishing activity com.android.locive/.ui.ConversationList
06-29 17:21:40.953: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{450f7ad8 com.android.locive/.ui.ComposeMessageActivity}
06-29 17:21:41.014: INFO/ARMAssembler(59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x384800:0x3848bc] in 452917 ns
06-29 17:21:51.992: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{44fbc270 com.android.locive/.ui.ConversationList}
06-29 17:21:51.994: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{450f7ad8 com.android.locive/.ui.ComposeMessageActivity}**
</code></pre>

<p>The method is</p>

<pre><code>private void initRecipientsEditor() {
    if (isRecipientsEditorVisible()) {
        return;
    }
    // Must grab the recipients before the view is made visible because getRecipients()
    // returns empty recipients when the editor is visible.
    ContactList recipients = getRecipients();

    ViewStub stub = (ViewStub) findViewById(R.id.recipients_editor_stub);
    if (stub != null) {
        //stub.inflate();
        **mRecipientsEditor =   (RecipientsEditor) stub.inflate();**
    } else {
        mRecipientsEditor = (RecipientsEditor)findViewById(R.id.recipients_editor);
        mRecipientsEditor.setVisibility(View.VISIBLE);
    }
</code></pre>

<p>The XML file for the RecipientsEditor class is</p>

<pre><code>FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"   
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"&gt;

&lt;!-- Layout for edittext and button --&gt;



    &lt;EditText
        android:id="@+id/recipients_editor"
        android:hint="@string/to_hint"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:lines="1"
                    /&gt;

&lt;!--
    &lt;style name="PlusButton"&gt;
&lt;item name="android:background"&gt;@drawable/btn_circle&lt;/item&gt;
&lt;item name="android:src"&gt;@drawable/ic_btn_round_plus&lt;/item&gt;
&lt;item name="android:contentDescription"&gt;@string/description_plus_button&lt;/item&gt;
&lt;/style&gt; 
--&gt;

   &lt;ImageButton
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_margin="3dip"
        android:src="@drawable/minibtn"
         /&gt;


&lt;/FrameLayout&gt;
</code></pre>
