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

查看:204
本文介绍了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();
        }       
    }
}

android清单文件

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>

推荐答案

在等待了很长时间这个答案之后,我已经解决了问题,并且我认为很多其他人将需要一个简单的解决方案来解决这个问题.

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时,可以从

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.

如果您的项目中没有目录库,请创建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文件,然后单击确定".现在它将显示在列表框中. 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.现在,单击确定"关闭属性"对话框.

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.

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

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天全站免登陆