FragmentActivity不能解析到一个类型 [英] FragmentActivity cannot be resolve to a type

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

问题描述

我开始学习Android平板电脑编程,我能更新我的Eclipse以及为Android的所有新的SDK。我开始从这个博客而测试中的应用在延长 FragmentActivity 收到这个错误我有谷歌,但没有得到任何解决方案。

我的项目是具有11级3.0版本创建的,其他所有的包都成功地应用在code,但只有这个 FragmentActivity 没能解决。

我错过任何图书馆或什么东西?

我的code

 公共类Testing_newActivity扩展FragmentActivity {//此处没有找到进口FragmentActivity得到错误包
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        如果(getResources()。getConfiguration()。方向
                == Configuration.ORIENTATION_LANDSCAPE){
            //如果屏幕现在是在横向模式下,我们可以显示
            //对话框中网上,所以我们不需要这个活动。
            完();
            返回;
        }

        如果(savedInstanceState == NULL){
            //在初始设置,插上的细节片段。
            DetailsFragment细节=新DetailsFragment();
            details.setArguments(getIntent()getExtras());

            getSupportFragmentManager()的BeginTransaction()。增加(
                    android.R.id.content,详情).commit();
        }
    }
}
 

Android清单文件

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.searce.testingnew
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <使用-SDK安卓的minSdkVersion =11/>

    <应用机器人:图标=@可绘制/ ic_launcher机器人:标签=@字符串/ APP_NAME>
        <活动机器人:标签=@字符串/ APP_NAME机器人:名称=。Testing_newActivity>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>

< /舱单>
 

解决方案

在很长一段时间这个答案我已经整理,但我想很多人需要这个问题的简单解决方案。

 此解决方案,谁也采用靛蓝或更低版本的Eclipse用户。仍然发现了未使用Eclipse和用于其他编辑器为Android谁另一用户。
 

好了,所以,当你扩展 FragmentActivity 与2.2或版本,不支持的片段,任何低版本的应用程序。您可以从的android.supportv4.jar这里或者你可以从这个使用Android SDK目录 .. \ Android的SDK \演员\机器人\ SUPPORT \ V4 并投入到项目中。

如果您的项目中没有目录库然后创建libs目录并粘贴此目录中的android.supportv4.jar文件。

现在从Eclipse项目工作空间。 选择项目/应用程序要在其中使用。右键单击项目,然后选择属性选项。在此选择 Java构建路径键,选择标签

现在单击Add罐会显示项目选择当前项目的当前列表。 现在展开这并转到库目录,选择android.supportv4.jar文件,然后单击确定。它会在列表框现在显示。 记住的jar文件添加为相对路径,路径而不是绝对路径,所以无论何时,如果你改变你的项目,或在另一台机器的目录中打开之后就会自动检测的项目目录。现在点击OK关闭属性对话框。

您可以能够导入 android.support.v4.app.FragmentActivity; 来把鼠标放在FragmentActivity或preSS的CTRL + SHIFT + O来导入丢失的文件。

希望你能现在得到FragmentActivity类。

如果您使用的是Eclipse JUNO再无需担心下载的支持jar文件。它会自动放到库目录中,并自动添加到您的项目路径。如果情况不是那么经过属性选项并添加。

一件事。如果你需要支持你的应用程序版本较低,然后建立与更高版本,并添加您此行到AndroidManifest.xml文件

 <使用-SDK
    安卓的minSdkVersion =3
    机器人:targetSdkVersion =15/>
 

1.5到4.0.1版本的设备,这将现在支持。

I am starting learning for android tablet programming and I am able to updated my Eclipse as well as all new sdk for android. I have start testing application from this blog while at extending the FragmentActivity getting this error I have google it but not getting any solution.

My project was created with 3.0 version having 11 level, all other packages are successfully used in the code but only this FragmentActivity was not able to resolve.

Am I missing any library or any thing?

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>

解决方案

After long time for this answer I have sorted but I think many people need simple solution for this question.

This solution for eclipse user who have using Indigo or lower version. Still finding for another user who have not use the eclipse and used another editor for android.

Ok so when you extending the FragmentActivity for your application with the version of 2.2 or any lower version which did not support the Fragment for that. 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 is no directory libs in your project then create libs directory and paste the android.supportv4.jar file in this directory.

Now from eclipse project workspace. Select your 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 project with selected current project. Now 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 can able to import the android.support.v4.app.FragmentActivity; to putting mouse on the FragmentActivity or press the ctrl+shift+o to import missing files.

Hope you can got now FragmentActivity class.

If you 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.

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.

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

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