Note that there are some explanatory texts on larger screens.

plurals
  1. POClassCastException: CustomFragment cannot be cast to android.app.Fragment / Using android.support.v4.app.Fragment
    primarykey
    data
    text
    <p>I am developing an application divided in one library and two applications : 1 for phones, the other for tablets. A lot of code and layout is defined in the library, and only a few parts are defined in the applications.</p> <p>I'm using fragments in an <code>Activity</code>, with a <code>ViewPager</code> for the phone version (layout and activity defined in the library, used with no change in the phone application). For the tablet version, I want to show my fragments (2) side by side, and not in a <code>ViewPager</code>, so I tried to build an XML layout like that :</p> <pre><code>&lt;....&gt; &lt;LinearLayout android:id="@+id/fragmentsParent" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;fragment android:id="@+id/f1" android:class="com.test.Fragment1" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="1" /&gt; &lt;fragment android:id="@+id/f2" android:name="com.test.Fragment2" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; &lt;/....&gt; </code></pre> <p>My problem is that the code is working on my phone application, but not on my tablet application. On this one, I get this exception stack :</p> <pre><code>07-11 17:41:14.032: E/AndroidRuntime(14754): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050) 07-11 17:41:14.032: E/AndroidRuntime(14754): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1782) 07-11 17:41:14.032: E/AndroidRuntime(14754): ... 11 more 07-11 17:41:14.032: E/AndroidRuntime(14754): Caused by: java.lang.ClassCastException: com.test.Fragment1 cannot be cast to android.app.Fragment 07-11 17:41:14.032: E/AndroidRuntime(14754): at android.app.Fragment.instantiate(Fragment.java:560) 07-11 17:41:14.032: E/AndroidRuntime(14754): at android.app.Fragment.instantiate(Fragment.java:535) 07-11 17:41:14.032: E/AndroidRuntime(14754): at android.app.Activity.onCreateView(Activity.java:4168) 07-11 17:41:14.032: E/AndroidRuntime(14754): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664) </code></pre> <p>The error messages talk about <code>android.app.Fragment</code> where I Would expect <code>android.support.v4.app.Fragment</code>.</p> <p>After searching the web, I checked these points :</p> <ul> <li>My activity extends <code>android.support.v4.app.FragmentActivity</code>,</li> <li>My fragments extend <code>android.support.v4.app.Fragment</code>,</li> <li>My application uses the support.v4 library.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload