4

我正在构建一个简单的Hello World应用,以了解Android兼容包。我能够获得该应用在3.2模拟器上运行,但是当我在2.3.3模拟器中运行它,我得到无法解析在Android 2.3.3上运行的具有兼容性包v4的FragmentActivity

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 

回答

4

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

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

+5

我也有问题。我发现你的评论,丹,并按照你的说法。右键单击项目,Android工具,添加支持库。诀窍! – Davek804

+0

谢谢Davek804,这么多日子里我一直很生气。不知道ADT团队是否发布了这个特定事情的官方声明! –

+0

是的,看看这个[回答](http:// stackoverflow。com/questions/11764195/unable-to-resolve-superclass-of-landroid-support-v4-app-fragmentactivity)。在导出构建路径中未选中的私有依赖可能是一个可能的问题。 – asgs

1

我有同样的问题,兼容性包没有正确内置到apk中。为了实现这一目标,您可以使用以下步骤:

developer.android.com:

要添加的图书馆之一到你的Android项目:

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. 
0

添加以下MyActivity进口:

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

即使您没有使用这些类别秒。

相关问题