3

互換性ライブラリを使用していますが、android.view.fragment のクラスが見つからないという例外が表示されます。正常にコンパイルされますが、クラッシュします。3.0 より前のときに使用すべき別のパッケージはありますか? すでにすべてのフラグメント クラスを android.support.v4.app.Frament に変更しましたが、レイアウトにあるものが原因でクラッシュします。私のSDKは4.03ですが、デバイスは2.3です。

レイアウトはこちら

    <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<fragment
    android:id="@+id/frag_series"
    android:layout_width="200dip"
    android:layout_height="match_parent"
    android:layout_marginTop="?android:attr/actionBarSize"
    class="com.authorwjf.hello_fragments.ListFrag" />
<fragment
    android:id="@+id/frag_capt"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.authorwjf.hello_fragments.DetailFrag" />
</LinearLayout>

LogCat:

08-08 14:53:21.644: E/AndroidRuntime(13056): Caused by: android.view.InflateException:     Binary    XML file line #6: Error inflating class fragment
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:200)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.app.Activity.setContentView(Activity.java:1647)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at com.authorwjf.hello_fragments.Main.onCreate(Main.java:11)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-08 14:53:21.644: E/AndroidRuntime(13056):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-08 14:53:21.644: E/AndroidRuntime(13056):    ... 11 more
08-08 14:53:21.644: E/AndroidRuntime(13056): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.authorwjf.hello_fragments-2.apk]
08-08 14:53:21.644: E/AndroidRuntime(13056):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
4

5 に答える 5

3

レイアウト XML で同じことを行います。

<android.support.v4.app.Fragment />

また、大文字小文字に注意してください。

于 2012-08-08T22:07:34.130 に答える
1

アクティビティが FragmentActivity を拡張しているかどうかを確認しますか? android.support.v4.app.FragmentActivity 正確には...

于 2013-06-20T12:28:24.987 に答える
0

FragmentActivity. それを追加すると問題が解決しました:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}
于 2013-06-05T10:34:40.660 に答える
0

私のSDKは4.03ですが、デバイスは2.3です。

私もこの問題を抱えていました。次に、デバイスの下位バージョンで実行している場合、サポート jar (android.support.v4) をビルド パスに含める必要があることを知りました。

Jar をビルド パスに含めた後、jar ファイルが順序の一番上にあることも確認する必要があります (Eclipse の [順序とエクスポート] オプションを使用)。

これらの2つのことが私の問題を解決しました..それが役立つことを願っています..

于 2013-09-10T06:15:41.337 に答える
0

私は同じ問題に遭遇しました。ここに解決策があります。

フラグメントを使用するアクティビティFragmentActivityは、単にではなく拡張する必要がありますActivity。 アクティビティのレイアウトでは、代わりに

引き続き使用できます<fragment /><android.support.v4.app.Fragment />

于 2014-05-12T22:54:57.370 に答える