I am trying to inflate a layout containing a Fragment using the backwards compatibility package and SDK level 10. I took the jar file and placed it in the libs folder of my project. I extended FragmentActivity.
It all works perfectly when I run at API level 11 on an XLarge screen device.
When I drop back to compiling against level 10, and running on a normal sized screen, I get failure at the point where it create a new Activity and inflate the fragment in it.
Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.motoappsummitagenda-1.apk] 04-01 01:07:14.311 2870 2870 E AndroidRuntime: at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
So it looks like something, somewhere is looking for android.view.fragment, and not the compatibility version, android.support.v4.app.Fragment. Of course, android.view.fragment won't be found on API level 10. But where is that android.view.fragment coming from?
The XML that is being inflated is
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.motorapp.SessionFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sessionfragment">
</fragment>
The code for it starts:
package com.motorapp;
import java.util.List;
import java.util.ListIterator;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.support.v4.app.*;
import android.support.v4.util.*;
import android.support.v4.*;
import android.support.v4.widget.*;
public class SessionFragment extends android.support.v4.app.Fragment {
The symptoms are similar to this problem, but I don't have those mistakes inflating fragments with compatibility package android
The android.compatibility.v4.android-support-v4 jar file is on my build path in Eclipse under Project > Properties > Java build path
I have in the manifest (and I have tried different variations of the name).
In getting started with fragments, I first used API 11 on a honeycomb device, and that all works perfectly. It is in getting the same code (modified to use the slightly different compatibility API) working with the compatibility library that I have this problem. Any ideas would be very welcome. Thanks, Peter
I just solved this problem in Android API 8 machine (Samsung Galaxy S).
Please change Activity
class to FragmentActivity
.
public class FragmentLayout extends Activity {}
-->
public class FragmentLayout extends FragmentActivity {}
public static class DetailsActivity extends Activity {}
-->
public static class DetailsActivity extends FragmentActivity {}
finally
getFragmentManager()
--> getSupportFragmentManager()
register android-support-v4.jar to Eclipse's referenced Libraries
put android-support-v4.jar to {root directory of your project}/libs directory
change to API 10 enum (ex:simple_list_item_1) from simple_list_item_activated_1
import android.support.v4.app.Fragment;
I had the same wrong class problem with the compatibility library and tried everything mentioned above with no luck. I finally figured it out: I was using the incorrect XML element Fragment
rather than correct one fragment
. Capitalization seems to matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With