Ksice
Ksice

Reputation: 3327

Android Fragments with compatible library

I can't make it work.

I found many similar question here, examples. But nothing help and nothing work. Does anyone have a working Fragments in Android 2.2 with android.support.v4 library? (If you are please upload it somewhere.)

I'm almost crying because I can't find what's wrong!

The error is the same as many of people have:

05-15 18:20:20.583: W/dalvikvm(1521): Unable to resolve superclass of Lmy/fragment/test/FragmentTestActivity; (8)
05-15 18:20:20.583: W/dalvikvm(1521): Link of class 'Lmy/fragment/test/FragmentTestActivity;' failed
05-15 18:20:20.593: D/AndroidRuntime(1521): Shutting down VM
05-15 18:20:20.593: W/dalvikvm(1521): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-15 18:20:20.703: E/AndroidRuntime(1521): FATAL EXCEPTION: main
05-15 18:20:20.703: E/AndroidRuntime(1521): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{my.fragment.test/my.fragment.test.FragmentTestActivity}: java.lang.ClassNotFoundException: my.fragment.test.FragmentTestActivity in loader dalvik.system.PathClassLoader[/data/app/my.fragment.test-1.apk]
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.os.Looper.loop(Looper.java:123)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at java.lang.reflect.Method.invokeNative(Native Method)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at java.lang.reflect.Method.invoke(Method.java:521)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at dalvik.system.NativeStart.main(Native Method)
05-15 18:20:20.703: E/AndroidRuntime(1521): Caused by: java.lang.ClassNotFoundException: my.fragment.test.FragmentTestActivity in loader dalvik.system.PathClassLoader[/data/app/my.fragment.test-1.apk]
05-15 18:20:20.703: E/AndroidRuntime(1521):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-15 18:20:20.703: E/AndroidRuntime(1521):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-15 18:20:20.703: E/AndroidRuntime(1521):     ... 11 more
05-15 18:20:23.423: I/Process(1521): Sending signal. PID: 1521 SIG: 9

SOLVED!!!! Who have this warnings before error:

05-16 10:08:00.033: W/dalvikvm(1695): Unable to resolve superclass of Lmy/fragment/test/FragmentTestActivity; (7)
05-16 10:08:00.076: W/dalvikvm(1695): Link of class 'Lmy/fragment/test/FragmentTestActivity;' failed

Should export android-support-v4 to right to your app:

Configure Java Build Path -> Order And Export tab -> set checkbox android-support-v4.jar

(Maybe need to remove existing one firstly)

it will moves this library to your apk (as I understand it)

Upvotes: 2

Views: 502

Answers (4)

Barak
Barak

Reputation: 16393

Since you are obviously just learning about this I'll expand on Warpzit's answer to try and help you out (you should accept his answer so he gets credit, since it is the correct one and he answered first).

This:

public class DetailsActivity extends FragmentActivity 

Needs to be this:

public class DetailsActivity extends Fragment

As do any other tabs you want to display as part of that first activity.

There should only be one FragmentActivity unless you are going to start a second activity (and leave the first) that will also have fragments, then the same applies.

Upvotes: 1

Warpzit
Warpzit

Reputation: 28152

You should have 1 FragmentActivity with fragments inside. What you are doing is trying to put activities (fragmentactivity) inside xml. That wont work. Try to only have 1 top level fragmentactivity and then make the other into fragments and then put those fragments inside your xml.

Upvotes: 4

Jave
Jave

Reputation: 31846

Try to replace android:name="classpath" with class=""classpath.

Upvotes: -1

Iulia Barbu
Iulia Barbu

Reputation: 1530

why do you have two activities named FragmentTestActivity? or is just writing error? have you declared it in manifest?

Upvotes: 0

Related Questions