无法解析在具有兼容包 v4 的 Android 2.3.3 上运行的 FragmentActivity

发布于 2024-12-09 21:50:37 字数 2272 浏览 1 评论 0原文

我正在构建一个简单的 hello world 应用程序来了解 Android 兼容性包。我能够让应用程序在 3.2 模拟器上运行,但是当我在 2.3.3 模拟器上运行它时,我得到

10-12 11:36:14.474: WARN/dalvikvm(469): Unable to resolve superclass of Lcom/example/MyActivity; (11) 
10-12 11:36:14.564: WARN/dalvikvm(469): Link of class 'Lcom/example/MyActivity;' failed 
10-12 11:36:14.564: DEBUG/AndroidRuntime(469): Shutting down VM 
10-12 11:36:14.584: WARN/dalvikvm(469): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
10-12 11:36:14.624: ERROR/AndroidRuntime(469): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example/com.example.MyActivity}: java.lang.ClassNotFoundException: com.example.MyActivity in loader dalvik.system.PathClassLoader[/data/app/com.example-1.apk]

所以显然它找不到 FragmentActivity (这是 com.example.MyActivity 的超级)。我只是不知道为什么。

需要注意的一些事情:

1)我正在遵循 上的教程http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/ 这不是很彻底。

2)我很确定我正在使用maven正确地将兼容性包构建到APK中。我在本地 Maven 存储库中安装了该 jar,并依赖它进行编译。我认为如果我没有正确构建它,它就无法在 3.2 模拟器上运行。

3)我尝试使用 IntelliJ 和 maven-compiler-plugin 进行构建。相同的结果。

任何帮助将不胜感激。谢谢。

编辑... 这是清单

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name=".MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".TutViewerActivity"
              android:label="@string/app_name" >
    </activity>
</application>
<uses-sdk android:minSdkVersion="7" />

和 MyActivity 定义

public class MyActivity extends FragmentActivity implements TutListFragment.OnTutSelectedListener

I'm building a simple hello world app to learn about the Android Compatibility Package. I'm able to get the app to run on the 3.2 emulator but when I run it on a 2.3.3 emulator I get

10-12 11:36:14.474: WARN/dalvikvm(469): Unable to resolve superclass of Lcom/example/MyActivity; (11) 
10-12 11:36:14.564: WARN/dalvikvm(469): Link of class 'Lcom/example/MyActivity;' failed 
10-12 11:36:14.564: DEBUG/AndroidRuntime(469): Shutting down VM 
10-12 11:36:14.584: WARN/dalvikvm(469): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
10-12 11:36:14.624: ERROR/AndroidRuntime(469): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example/com.example.MyActivity}: java.lang.ClassNotFoundException: com.example.MyActivity in loader dalvik.system.PathClassLoader[/data/app/com.example-1.apk]

So obviously it can't find FragmentActivity (which is the super of com.example.MyActivity). I just don't know why.

Some things to note:

1) I'm following the tutorials at http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/ which isn't very thorough.

2) I'm pretty sure I'm building the compatibility package into the APK correctly with maven. I installed the jar in my local maven repository and am depending on it with compile. I think that if I weren't building it in correctly it wouldn't be running on the 3.2 emulator.

3) I've tried building with IntelliJ and the maven-compiler-plugin. Same result.

Any help would be greatly appreciated. Thanks.

EDIT...
Here's the Manifest

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name=".MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".TutViewerActivity"
              android:label="@string/app_name" >
    </activity>
</application>
<uses-sdk android:minSdkVersion="7" />

and the MyActivity definition

public class MyActivity extends FragmentActivity implements TutListFragment.OnTutSelectedListener

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过期以后 2024-12-16 21:50:37

我遇到了同样的问题,问题是兼容性包没有正确包含在内。该异常是不明确的,因为它说它找不到 MyActivity,但完整的堆栈跟踪将显示它无法链接的 FragmentActivity。检查范围,并确保您的存储库中包含正确的版本,并且它确实在构建时包含在内。

如果您仍然遇到此问题,请尝试在此处包含您的 pom.xml。

I had the same issue, and the problem was the compatibility package was not getting included properly. The exception is ambiguous, as it says it can't find the MyActivity, but the full stack trace will show the FragmentActivity that it can't link. Check the scope, and make sure correct version is in your repository, and it is indeed being included at build time.

If you're still having this issue, try including your pom.xml here.

内心荒芜 2024-12-16 21:50:37

我遇到了同样的问题,兼容性包没有正确构建到apk中。为此,您可以使用以下步骤:

来自 developer.android.com:< /a>

要将其中一个库添加到您的 Android 项目中:

在您的 Android 项目中,在项目根目录下创建一个名为 libs 的目录(位于 src/、res/ 等旁边)
找到要使用的库的 JAR 文件并将其复制到 libs/ 目录中。

例如,支持 API 级别 4 及更高级别的库位于 /extras/android/support/v4/android-support-v4.jar。
将 JAR 添加到您的项目构建路径。

在 Eclipse 中,右键单击 Package Explorer 中的 JAR 文件,选择 Build Path >添加到构建路径。

I had the same problem, the compatibility package was not built into the apk properly. To achieve that, you can use the following steps:

From developer.android.com:

To add one of the libraries to your Android project:

In your Android project, create a directory named libs at the root of your project (next to src/, res/, etc.)
Locate the JAR file for the library you want to use and copy it into the libs/ directory.

For example, the library that supports API level 4 and up is located at <sdk>/extras/android/support/v4/android-support-v4.jar.
Add the JAR to your project build path.

In Eclipse, right-click the JAR file in the Package Explorer, select Build Path > Add to Build Path.
萌化 2024-12-16 21:50:37

将以下内容添加到 MyActivity 的导入中:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

即使您没有使用这些类。

Add the following to MyActivity's imports:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

Even if you're not using those classes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文