首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActivityNotFoundException on FragmentActivity

ActivityNotFoundException on FragmentActivity
EN

Stack Overflow用户
提问于 2012-03-25 11:50:48
回答 2查看 5.9K关注 0票数 1

在Play Store中,我确实有很多普通的基于活动的应用程序。两天后,我试着用碎片做我的第一步。我还是不明白。我读过大部分关于片段的文档、博客和指南,但我愚蠢的简单测试应用拒绝从ClassNotFoundException on MyActivity开始。

因此,我到目前为止所做的是:

启动FragmentActivity称为MyActivity:

代码语言:javascript
复制
public class MyActivity extends FragmentActivity {

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

        setContentView(R.layout.myactivity);
    }
}

下面是布局/myactivity.xml:

代码语言:javascript
复制
<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文件:

代码语言:javascript
复制
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>

说我愚蠢,但我总是在ActivityNotFoundException开始时得到一个名为MyActivity的FragmentActivity。

任何帮助都是非常感谢的。

编辑

我使用了几天前最新的v4兼容性包。我几乎每10分钟发布一次清洁项目--不去。

这是宣言:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
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包v4创建了一个新项目,将所有内容简化为MyActivity和一个片段->相同的错误。我甚至用以前的支持v4包(第6版)进行了测试。

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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-26 10:19:03

我不知道这是否能解决你的问题,但是看一下你的截图,我觉得除了Referenced Libraries之外,一切都是正确的。这不应该再出现了,因为最新的ADT 17会自动检测libs文件夹中的所有jars。您可以从构建路径中删除对android的显式引用,从而摆脱Referenced Libraries项。

我遇到了一个非常类似的问题,在我读到this blog post之前,我一直很困惑,因为它有很多关于这个问题的信息,所以即使删除Referenced Libraries不起作用,它也可能值得一读。

票数 11
EN

Stack Overflow用户

发布于 2012-03-25 17:58:01

有些事情似乎不像预期的那样起作用。将兼容性jar复制到文件夹库中,然后重新编译和重新打包。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9859899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档