我正在尝试 this blog 的应用程序.扩展 FragmentActivity
时,出现以下错误:
`FragmentActivity` was not able to resolve.
我是否缺少任何图书馆或其他任何东西?
我的代码:
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();
}
}
}
安卓 list 文件
<?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>
最佳答案
等待这个答案很久之后,我已经整理好了,我想很多其他人都需要一个简单的解决方案来解决这个问题。
警告:此解决方案适用于使用 Indigo 或更低版本的 eclipse 用户。仍在寻找使用其他 Android IDE 的解决方案用户。
为您的应用程序扩展 2.2 或更低版本的 FragmentActivity
时,您可以从 here 下载 android.supportv4.jar或者您可以从您的 android-sdk 目录 ..\android-sdk\extras\android\support\v4
中获取它并放入您的项目中。
如果您的项目中没有目录libs,则创建libs目录并将android.supportv4.jar文件粘贴到该目录中。
来自 Eclipse 项目工作区:
选择要在其中使用的 project/application
。右键单击 Project
并选择 Properties
选项。在此选择 Java build path
并选择选项卡 Libraries
现在点击添加 jar 。它将显示当前项目列表以及选定的当前项目。
展开这个并进入 libs 目录并选择 android.supportv4.jar 文件然后单击确定。它现在将显示在列表框中。 请记住将jar文件添加为相对路径路径而不是绝对路径,所以每当您更改项目目录或在另一台机器上打开时,都会自动检测项目目录。
现在点击确定关闭属性对话框。
您可以导入 android.support.v4.app.FragmentActivity;
,方法是将鼠标放在 FragmentActivity 上或按 ctrl+shift+o 导入丢失的文件。
希望你现在能拿到 FragmentActivity 类。
如果您使用的是 eclipse juno,则无需担心下载支持 jar 文件。它将自动放入 libs 目录并自动添加到您的项目路径中。如果没有,请通过 Properties
选项并添加它。
还有一件事如果您需要支持较低版本的应用程序,则使用较高版本构建并将您的这一行添加到您的 androidmanifest.xml 文件中
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="15" />
这现在将支持 1.5 到 4.0.1 版本的设备。
关于android - FragmentActivity 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8164886/