FragmentActivity 无法解析为类型 [英] FragmentActivity cannot be resolved to a type

查看:22
本文介绍了FragmentActivity 无法解析为类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 此博客中的应用程序.在扩展 FragmentActivity 时,我收到以下错误:

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?

我的代码:

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();
        }       
    }
}

安卓清单文件

<?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>

推荐答案

等了好久这个答案,我已经整理好了,我想很多其他人会需要一个简单的解决方案来解决这个问题.

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.

>

警告:此解决方案适用于使用 Indigo 或更低版本的 eclipse 用户.仍在寻找使用其他 Android IDE 的解决方案用户.

当为您的 2.2 或更低版本的应用程序扩展 FragmentActivity 时,您可以从 这里 或者你可以从你的 android-sdk 目录 ..android-sdkextrasandroidsupportv4 并放入您的项目中.

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-sdkextrasandroidsupportv4 and put into your project.

如果您的项目中没有目录libs,请创建libs目录并将android.supportv4.jar文件粘贴到该目录中.

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

从 eclipse 项目工作区:选择要在其中使用的 project/application.右键单击 Project 并选择 Properties 选项.在此选择 Java build path 并选择标签 Libraries

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

现在点击添加罐子.它将显示当前选择的项目列表.

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

展开它并转到 libs 目录并选择 android.supportv4.jar 文件,然后单击确定.它现在将显示在列表框中.记住将jar文件添加为相对路径而不是绝对路径,所以每当你改变项目目录或在另一台机器上打开时,都会自动检测项目目录. 现在点击Ok关闭属性"对话框.

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.

您可以导入 android.support.v4.app.FragmentActivity; 将鼠标放在 FragmentActivity 上或按 ctrl+shift+o 导入丢失的文件.

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.

希望你现在可以得到 FragmentActivity 类.

Hope you can got now FragmentActivity class.

如果您使用的是 eclipse juno,则无需担心下载支持 jar 文件.它会自动放入 libs 目录并自动添加到您的项目路径中.如果没有,则通过 Properties 选项并添加它.

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.

还有一件事如果您需要支持较低版本的应用程序,请使用较高版本构建并将此行添加到您的 androidmanifest.xml 文件中

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" />

现在将支持 1.5 到 4.0.1 版本的设备.

this will now support for 1.5 to 4.0.1 version devices.

这篇关于FragmentActivity 无法解析为类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆