0

アクティビティによって拡張される XML レイアウト ファイルがあります。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
>
<LinearLayout
      android:id="@+id/content2"
      android:background="@color/lighter_gray"
      android:layout_width="match_parent"
      android:orientation="horizontal"
      android:layout_height="match_parent" >

<fragment class="com.xyz.fragments.TabFragment"
          android:id="@+id/tabs"
  android:layout_weight="1"
  android:layout_width="0px"
  android:layout_height="match_parent"
  />
<FrameLayout
  android:id="@+id/fragment_holder"
  android:layout_weight="2"
  android:layout_width="0px"
  android:layout_height="match_parent" />

  </LinearLayout>
</RelativeLayout>

Activity は FragmentActivity (v4 ライブラリから) のサブクラス (直接ではない) です。

さて、com.xyz.fragments.TabFragment には、次のクラス宣言があります。

....
import android.support.v4.app.FragmentTransaction;
import roboguice.fragment.RoboListFragment;

public class TabFragment extends RoboListFragment {

.... 
....

実行中にアプリがクラッシュし、adb logcat に次のエラーが表示されます。

java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.xyz/com.xyz.xxActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class fragment

したがって、22行目はxmlレイアウトのこの行とまったく同じです

fragment class="com.xyz.fragments.TabFragment"

赤い下線が引かれています...そして、TabFragmentはandroid.app.fragmentに割り当てられないと言われています

わかりました。サポート ライブラリ v4 の roboguice の FragmentList を使用していますが、android.app.fragment とは異なります。

それで、なにかお手伝いできますか?これがアプリがクラッシュした理由だと思います。

以下の完全なスタック トレース

0-25 20:59:54.535: INFO/ApplicationPolicy(1903): isApplicationInstallationEnabled: pkg com.xyz 10-25 20:59:55.455: INFO/PackageManager(1903): 非システム パッケージの削除: com.xyz 10-25 20:59:55.455: INFO/ActivityManager(1903): 強制停止パッケージ com.xyz uid=10017 10-25 20:59:55.610: INFO/PackageManager(1903): ICS_DEBUG scanPackageLI が com.xyz 10-25 20:59 に入力されました:55.610: INFO/PackageManager(1903): com.xyz 10-25 20:59:55.615 の ICS_DEBUG チェック: INFO/PackageManager(1903): dexopt を実行中: com.xyz 10-25 20:59:58.390: INFO/ ActivityManager(1903): パッケージの強制停止 com.xyz uid=10017 10-25 20:59:59.305: DEBUG/PackageManager(1903): /data/app/com.xyz-2.apk にインストールされた新しいパッケージ 10-25 20 :59:59.705: INFO/ActivityManager(1903): 強制停止パッケージ com.xyz uid=10017 10-25 20:59:59.875: DEBUG/Launcher.LauncherModel(2152): --> package:com.xyz 10-25 21:00:00.050: INFO/SocialHub(6289): [UinboxReceiver] onReceive() >> インテント.getData(): com.xyz 10-25 21:00:00.345: DEBUG/Launcher.LauncherModel(2152 ): --> 更新パッケージ com.xyz 10-25 21:00:00.345: DEBUG/Launcher.LauncherModel(2152): --> パッケージ:com.xyz 10-25 21:00:00.640: INFO/DebugDb(2152 ): アプリ情報を更新 -1 com.sec.android.app.twlauncher.ApplicationInfo xyz -1 4 15 75|-1|-1|-1|-1|0 com.sec.android.app.twlauncher.ApplicationInfo@ 421323f0 10-25 21:00:01.675: INFO/ActivityManager(1903): pid 7524 10-25 21:00:01.775 から {flg=0x10000000 cmp=com.xyz/.TabActivity} を開始: INFO/ActivityManager(1903):アクティビティ com.xyz/.TabActivity の proc com.xyz を開始します: pid=7536 uid=10017 gids={3003} java.lang.RuntimeException: アクティビティ ComponentInfo{com.xyz/com.xyz.TabActivity} を開始できません: android. view.InflateException:バイナリ XML ファイルの 22 行目: com.xyz.TabActivity.onCreate(TabActivity.java:25) 10-25 21:00:24.225 でクラス フラグメントを拡張する際にエラーが発生しました: INFO/ActivityManager(1903): プロセス com.xyz (pid 7536)死亡しました。

4

2 に答える 2

1

nameそうではない使い方class

<fragment android:name="com.cyz.fragments.TabFragment"
        android:id="@+id/fragment_tab"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent" />

フラグメントが接続されているアクティビティが拡張されていることを確認してくださいRoboFragmentActivity

フラグメントで onCreateView をオーバーライドしていることを確認してください

public static class ExampleFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.example_fragment, container, false);
    }
}

また、何か他のことをしようとする前に、必ずsuper.onCreate(savedInstanceState);アクティビティを呼び出してください。onCreate()

于 2012-10-26T03:49:03.160 に答える
0

確かではありませんが、すべてのフラグメントでスーパークラスを呼び出しており、それは私にとってはうまくいきます。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    return inflater.inflate(R.layout.my_fragment, container, false);
}

それが機能するかどうかを確認してください。

于 2012-10-26T18:38:45.300 に答える