FragmentActivity cannot be resolved to a type
Asked Answered
K

4

29

I'm trying the application from this blog. While extending the FragmentActivity, I'm getting the following error:

`FragmentActivity` was not able to resolve.

Am I missing any library or anything else?

My code:

public class Testing_newActivity extends FragmentActivity { // here the FragmentActivity getting error package not found for import
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        if (getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE) {
            // If the screen is now in landscape mode, we can show the
            // dialog in-line so we don't need this activity.
            finish();
            return;
        }

        if (savedInstanceState == null) {
            // During initial setup, plug in the details fragment.
            DetailsFragment details = new DetailsFragment();
            details.setArguments(getIntent().getExtras());

            getSupportFragmentManager().beginTransaction().add(
                    android.R.id.content, details).commit();
        }       
    }
}

android manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.searce.testingnew"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />

    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
        <activity android:label="@string/app_name" android:name=".Testing_newActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Keratoid answered 17/11, 2011 at 9:34 Comment(1)
Go through your imports and make sure all the needed are there. (If you post some code/error log/something it will be easier to help).Philodendron
K
45

After waiting a long time for this answer, I have sorted things out, and I think that many other people will need a simple solution for this question.

Warning: This solution is for the eclipse user who uses Indigo or lower version. Still looking for solutions users who use other IDE's for android.

When extending the FragmentActivity for your application with version of 2.2 or lower, you can download the android.supportv4.jar from here or you can get this from your android-sdk directory ..\android-sdk\extras\android\support\v4 and put into your project.

If there are no directory libs in your project, create libs directory and paste the android.supportv4.jar file in this directory.

From eclipse project workspace: Select project/application in which you want to use. Right click on Project and select Properties option. In this select Java build path and select the tab Libraries

enter image description here

Now click on Add Jar. It will display current list of projects with selected current project.

Expand this and go to the libs directory and select android.supportv4.jar file then click ok. It will display in list box now. Remember add the jar file as relative path path not as absolute path, so whenever if you change the directory of your project or open in another machine then will detect automatically for the project directory. Now click on Ok to close the Properties dialog.

You are able to import the android.support.v4.app.FragmentActivity; by placing mouse over the FragmentActivity or pressing the ctrl+shift+o to import missing files.

Hope you can got now FragmentActivity class.

If you are using the eclipse juno, then no need to worry for downloading the support jar file. It will automatically put into the libs directory and automatically added to your project path. If in case not then go through the Properties option and add it.

One more thing If you need to support your application for lower version then build with the higher version and add your this line into your androidmanifest.xml file

<uses-sdk
    android:minSdkVersion="3"
    android:targetSdkVersion="15" />

this will now support for 1.5 to 4.0.1 version devices.

Keratoid answered 12/9, 2012 at 7:31 Comment(1)
This helped me! However i pressed Add External JARs...Postrider
D
37

If you are using eclipse and windows, here is how you can get rid of this error.

Right click on your project folder->Build path-> Configure build path-> 
Add External Jars -> select "android-support-v4.jar" file (It'll be located in Android "android-sdk-windows\extras\android\support")
then click OK.
Dumbfound answered 28/6, 2012 at 5:30 Comment(1)
then what to do for WatchActivity cannot be resolved to a typeBan
Z
5

you have to add external android support Jar to your class path e.g. in my case I added android-support-v4.jar its generally located in the {android_home}\extras\android\support\v4 directory. I am using windows XP and in my case its located at C:\Program Files\Android\android-sdk\extras\android\support\v4

Hope this helps to whoever is looking for answer.

Zooplasty answered 25/4, 2012 at 22:38 Comment(0)
C
2

FragmentActivity is part of the compatibility library and not Android 3.0 sdk. You don't need to use it unless you want backward compatibility.

Not sure why this is mentioned here may be its a project specific class.

Try looking at HCGallery Sample shipped with the sdk

Cloraclorinda answered 17/11, 2011 at 9:41 Comment(1)
so which library is for this?Keratoid

© 2022 - 2024 — McMap. All rights reserved.