4

I'm struggling with this error and I really can't get it right. I try to import android.support.v13.app.FragmentActivity; into a class but it gives me the error: The import android.support.v13.app.FragmentActivity cannot be resolved. I want to mention that I have both v13 and v4 in libs folder. I used Clean,Android Support Library and Fix Project Properties. The target device is 2.3.3 if that matters. Thank you. I really really hope that someone can help me. EDIT: After editing v4, a lot of errors are disappearing and I've got only 2 more. I'm very beginner in android so if you could explain me what is wrong here:

private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
    public ScreenSlidePagerAdapter(FragmentManager fm) {
        super(fm); //Error: The constructor Fragmentstagepageadapter(FragmentManager) is undefined
    }

@Override
public **Fragment** getItem(int position) { //And Here: The return type is incompatible
    return ScreenSlidePageFragment.create(position);
}

@Override
public int getCount() {
    return NUM_PAGES;
}

}

Greg Giacovelli
  • 10,164
  • 2
  • 47
  • 64
  • Have you added the libraries to your build path? Just right-click on the project and the menu item "Java Build Path" will be listed. Select this and add the libraries to your path. – lynvie Jan 02 '13 at 08:16
  • I answered a very similar question here: http://stackoverflow.com/questions/14111898/the-import-android-support-v13-app-fragmentactivity-cannot-be-resolved – lynvie Jan 02 '13 at 20:05
  • 1
    this helped me for a quite similar issue : http://stackoverflow.com/questions/3642928/adding-a-library-jar-to-an-eclipse-android-project?lq=1 – hornetbzz Oct 14 '13 at 16:10

2 Answers2

2

FragmentActivity is part of the v4 folder though right? v13 just means API 13 and above will use the classes in that folder. So while you may have that folder, I bet it doesn't have FragmentActivity in it :) Change your imports to have the v4 rather than the v13.

http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

So you know you can't use Fragment from the OS if you are using the SupportLib, you have to use only the Fragment classes inside the SupportLib. This include Fragment itself.

http://developer.android.com/reference/android/support/v4/app/Fragment.html vs http://developer.android.com/reference/android/app/Fragment.html.. Basically anything inside of android.app that has to do with Fragments, cannot be used with your SupportLib classes. They are not the same class hierarchy nor are they compatible.

Greg Giacovelli
  • 10,164
  • 2
  • 47
  • 64
2

This is the answer I gave to a very similar question:

Change the "import android.support.v13.app.FragmentActivity" to "import android.support.v4.app.FragmentActivity"

For the undefined part, try this syntax:

public class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter (android.support.v4.app.FragmentManager fm) {
    super(fm);
}

and:

@Override
public android.support.v4.app.Fragment getItem(int position) {
    return ScreenSlidePagerAdapter.create(position);
}
lynvie
  • 1,028
  • 1
  • 14
  • 25