1

こんにちは、Android 2.3.3の使用中にこの例外が発生します:

android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>

このメソッドで例外が発生します:(フラグメントを作成する場合)

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    if (container == null) {
        // We have different layouts, and in one of them this
        // fragment's containing frame doesn't exist. The fragment
        // may still be created from its saved state, but there is
        // no reason to try to create its view hierarchy because it
        // won't be displayed. Note this is not needed -- we could
        // just run the code below, where we would create and return
        // the view hierarchy; it would just never be used.
        return null;
    }
    try {
        //exception here
        theLayout = (LinearLayout) inflater.inflate(R.layout.fragment1, container, false);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return theLayout;
}

これは、Activityに移動し、FragmentActivityに戻ってタブを切り替えると発生します。

私はこれのために何をすべきですか?

ありがとう。

4

1 に答える 1

0

同じエラーが発生しました(ただし、MonoDroidとC#を使用しています)。私の場合、<fragment>タグを含むレイアウトを膨らませようとしましたが、OS(Android 2.3.3)はフラグメントを認識していません。

私にとっての解決策は、Androidサポートパッケージv4(android-support-v4.jar、<android-sdk>/extras/android/support/v4フォルダーにあります)を使用することでした。次に、SupportingFragmentManagerを使用してフラグメントを作成しました。

サンプルコード(Javaに簡単に変換できる)を含むMonoDroidの説明は、次の場所にあります:http ://docs.xamarin.com/android/tutorials/Fragments/Part_4_-_Pproving_Backwards_Compatibility_with_the_Android_Support_Package

于 2012-09-03T11:58:07.293 に答える