Failed to resolve FragmentActivity running on Android 2.3.3 with v4 compatibility pack

I am creating a simple greeting application to find out about the Android compatibility pack. I can make the application run on emulator 3.2, but when I run it on emulator 2.3.3, I get

10-12 11:36:14.474: WARN/dalvikvm(469): Unable to resolve superclass of Lcom/example/MyActivity; (11) 10-12 11:36:14.564: WARN/dalvikvm(469): Link of class 'Lcom/example/MyActivity;' failed 10-12 11:36:14.564: DEBUG/AndroidRuntime(469): Shutting down VM 10-12 11:36:14.584: WARN/dalvikvm(469): threadid=1: thread exiting with uncaught exception (group=0x40015560) 10-12 11:36:14.624: ERROR/AndroidRuntime(469): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example/com.example.MyActivity}: java.lang.ClassNotFoundException: com.example.MyActivity in loader dalvik.system.PathClassLoader[/data/app/com.example-1.apk] 

Thus, it is obvious that he cannot find FragmentActivity (which is the supercomputer com.example.MyActivity). I just don’t know why.

Some notes:

1) I follow tutorials at http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/ , which is not very thorough.

2) I am sure that I am correctly creating the compatibility package in the APK using maven. I installed the jar in my local maven repository and depending on this with compilation. I think that if I did not build it correctly, it would not work on the 3.2 emulator.

3) I tried to build with IntelliJ and the maven-compiler-plugin. The same result.

Any help would be greatly appreciated. Thanks.

EDIT ... Here's the manifest

 <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" /> <uses-permission android:name="android.permission.INTERNET" /> <application android:label="@string/app_name" android:icon="@drawable/icon"> <activity android:name=".MyActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".TutViewerActivity" android:label="@string/app_name" > </activity> </application> <uses-sdk android:minSdkVersion="7" /> 

and definition of MyActivity

 public class MyActivity extends FragmentActivity implements TutListFragment.OnTutSelectedListener 
+4
source share
3 answers

I had the same problem and the problem was that the compatibility pack was not included properly. The exception is ambiguous because it says it cannot find MyActivity, but a full stack trace will show a FragmentActivity that it cannot reference. Check the scope and make sure that the correct version is in your repository, and that it is really included at build time.

If you still have this problem, try including pom.xml here.

+4
source

I had the same problem, the compatibility package was not built into apk correctly. To do this, you can use the following steps:

From developer.android.com:

To add one of the libraries to an Android project:

 In your Android project, create a directory named libs at the root of your project (next to src/, res/, etc.) Locate the JAR file for the library you want to use and copy it into the libs/ directory. For example, the library that supports API level 4 and up is located at <sdk>/extras/android/support/v4/android-support-v4.jar. Add the JAR to your project build path. In Eclipse, right-click the JAR file in the Package Explorer, select Build Path > Add to Build Path. 
+1
source

Add the following to the MyActivity import list:

 import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; 

Even if you are not using these classes.

0
source

All Articles