2012-03-25 127 views
1

Play商店中确实有很多普通的旧的基于活动的应用程序。自从两天以来,我尝试使用Fragments来完成我的第一步。我仍然不明白。我已经阅读了大多数关于碎片的文档和博客以及指南,但我的愚蠢的简单测试应用程序拒绝以MyActivity上的ClassNotFoundException开始。FragmentActivity上的ActivityNotFoundException

因此,这里是我所做的迄今:

起始FragmentActivity称为MyActivity:

public class MyActivity extends FragmentActivity { 

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

     setContentView(R.layout.myactivity); 
    } 
} 

这里的布局/ 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 [email protected] 
    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 [email protected] 
    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和一个片段 - >相同的错误。我甚至使用以前的Support v4软件包(版本6)进行测试。

这些是我在Android开发(市场上的大量应用程序)近三年后第一次使用Fragments。似乎这整个事情都被打破了。

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

enter image description here

+2

请分享清单文件 – 2012-03-25 11:57:58

+0

似乎是一个清单问题 – Blackbelt 2012-03-25 11:58:15

+0

也分享你的日志中的行,可能会在原因:) :) – erbsman 2012-03-25 12:15:55

回答

11

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

我有一个非常类似的问题,并完全难住了一段时间,直到我读了this blog post有很多关于这个问题的信息,所以它可能值得一读,即使删除Referenced Libraries不起作用。

+1

啊,我明白了,谢谢。这似乎有伎俩。 – 2012-03-26 16:14:10

+0

解决了我的问题。谢谢! – Stark 2012-06-20 10:07:49

0

东西似乎预计将无法正常工作。 将兼容jar复制到一个文件夹库,然后重新编译并重新打包

+0

请在我的原始文章中查看编辑3。我做了几乎所有事情,重新安装了支持包(实际上是之前和之后的一对一),创建了一个新的Android项目,将文件分解为一个活动和一个片段。同样的错误。这里发生了什么事?有人用最新的SDK工具,最新的Eclipse和最新的测试过吗? – 2012-03-26 08:52:20

+0

检查这篇博文 - 它建议做我刚才写的https://plus.sandbox.google.com/109385828142935151413/posts/RL91VJd1yti – 2012-03-26 10:05:38

+0

我确实在这个网站上找不到错误。 – 2012-03-26 16:05:07