2012-03-25 81 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