FragmentActivity上的ActivityNotFoundException

时间:2012-03-25 11:50:48

标签: android fragment android-fragmentactivity

我在Play商店中确实有很多基于活动的简单应用程序。两天后,我尝试用Fragments做我的第一步。我还是不明白。我已经阅读了大部分关于Fragments的所有文档和博客以及指南,但我的愚蠢的简单测试应用程序拒绝以MyActivity上的ClassNotFoundException开头。

所以这就是我到目前为止所做的:

起始的FragmentActivity称为MyActivity:

public class MyActivity extends FragmentActivity {

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        setContentView(R.layout.myactivity);
    }
}

这是layout / myactivity.xml:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

    <fragment
        class="com.test.app.Table1List"
        android:id="@+id/table1list"
        android:layout_height="match_parent"
        android:layout_width="match_parent" />
</LinearLayout>

这是ListFragment及其XML文件:

public class Table1List extends ListFragment {

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        if (viewGroup == null) {
            return null;
        }

        return layoutInflater.inflate(R.layout.table1list, viewGroup);
    }
}

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ListView
        android:drawSelectorOnTop="false"
        android:fastScrollEnabled="true" 
        android:id="@id/android:list"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent" />

    <TextView
        style="@style/TextViewMedium"
        android:id="@id/android:empty"
        android:text="@string/txt_noresult" />
</LinearLayout>

叫我愚蠢,但我总是在FragmentActivity启动时得到一个名为MyActivity的ActivityNotFoundException。

非常感谢任何帮助。

修改

我从几天前开始使用最新的v4兼容包。我差不多每10分钟发一次干净的项目 - 不行。

这是清单:

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="1"
    android:versionName="1.0"
    package="com.test.app" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="11" />

    <application
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/txt_appname" >

        <activity
            android:label="@string/txt_appname"
            android:name="MyActivity" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

编辑2 :这是LogCat:

Unable to resolve superclass of Lcom/test/app/MyActivity; (25)
Link of class 'Lcom/test/app/MyActivity;' failed
Shutting down VM
threadid=3: thread exiting with uncaught exception (group=0x4001b188)
    Uncaught handler: thread main exiting due to uncaught exception
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.test.app/com.test.app.MyActivity}: java.lang.ClassNotFoundException: com.test.app.MyActivity in loader dalvik.system.PathClassLoader@44bfda38
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.ClassNotFoundException: com.test.app.MyActivity in loader dalvik.system.PathClassLoader@44bfda38
    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
    ... 11 more

编辑3 :我确实重新安装了支持包,用Compatability Package v4创建了一个新项目,将所有内容都剥离到了MyActivity和一个片段 - &gt;同样的错误。我甚至使用之前的Support v4软件包(版本6)进行了测试。

这是我在Android开发近三年后使用Fragments的第一步(市场上有很多应用程序)。似乎整件事都破了。

这是eclipse中的项目树 - 任何帮助仍然非常需要。

enter image description here

2 个答案:

答案 0 :(得分:11)

我不知道这是否能解决您的问题,但查看截图,除Referenced Libraries项外,一切看起来都不正确。那不应该再存在,因为最新的ADT版本17会自动检测libs文件夹中的所有jar。您可以通过从构建路径中删除对android支持jar的显式引用来删除Referenced Libraries项。

我遇到了一个非常类似的问题,并且在我阅读this blog post之前已经完全难过了,因为它有很多关于这个问题的信息所以即使删除了Referenced Libraries也不值得一读#39; t work。

答案 1 :(得分:0)

似乎没有按预期工作。 将兼容性jar复制到文件夹libs,然后重新编译并重新打包