2

Android 2.2 を対象とする Android 互換性ライブラリを使用しています。配列アダプターで ListFragment を使用すると正常に動作しますが、simpleCursorAdapter を使用するとクラッシュします。ListFragment のコードは次のとおりです。

public class Fragment1 extends ListFragment {

    private SQLiteDatabase db;
    private Cursor c;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      DbManager dbm = new DbManager (getActivity(), "mainDb", null, 3);
      db = dbm.getWritableDatabase();
      c = db.rawQuery("SELECT * FROM navegacion", null);
      c.moveToFirst();

      ListAdapter adapter = new SimpleCursorAdapter( getActivity().getApplicationContext(), R.layout.list_item, c, new String[]{"texto"}, new int []{R.id.mainListText}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
      setListAdapter(adapter);


    }
 }

DbManager は SqliteHelper を拡張したクラスです。うまくいかない理由がわかりません。以前は listActivity で動作していました。コンストラクターにフラグを追加しました。このフラグメントをインスタンス化すると、デバイスはアプリケーションが中断されたことを通知し、アプリケーションを閉じます。誰かが私が間違っていることを知っていますか?

前もって感謝します。


編集。logcat からのスタック トレースは次のとおりです。

05-22 19:32:17.093: W/dalvikvm(12680): VFY: unable to resolve virtual method 4091: Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout;.onHoverEvent (Landroid/view/MotionEvent;)Z
05-22 19:32:17.103: W/dalvikvm(12680): VFY: unable to resolve virtual method 2878: Landroid/widget/FrameLayout;.getAlpha ()F
05-22 19:32:17.103: W/dalvikvm(12680): VFY: unable to resolve virtual method 2879: Landroid/widget/FrameLayout;.getTranslationY ()F
05-22 19:32:17.103: W/dalvikvm(12680): VFY: unable to resolve virtual method 2882: Landroid/widget/FrameLayout;.setAlpha (F)V
05-22 19:32:17.103: W/dalvikvm(12680): VFY: unable to resolve virtual method 2890: Landroid/widget/FrameLayout;.setTranslationY (F)V
05-22 19:32:17.123: W/dalvikvm(12680): VFY: unable to resolve virtual method 257: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
05-22 19:32:17.123: W/dalvikvm(12680): VFY: unable to resolve virtual method 254: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
05-22 19:32:17.173: W/dalvikvm(12680): VFY: unable to resolve virtual method 2660: Landroid/view/ViewGroup;.getAlpha ()F
05-22 19:32:17.173: W/dalvikvm(12680): VFY: unable to resolve virtual method 2666: Landroid/view/ViewGroup;.getTranslationX ()F
05-22 19:32:17.173: W/dalvikvm(12680): VFY: unable to resolve virtual method 2667: Landroid/view/ViewGroup;.getTranslationY ()F
05-22 19:32:17.173: W/dalvikvm(12680): VFY: unable to resolve virtual method 2682: Landroid/view/ViewGroup;.setAlpha (F)V
05-22 19:32:17.173: W/dalvikvm(12680): VFY: unable to resolve virtual method 2686: Landroid/view/ViewGroup;.setTranslationX (F)V
05-22 19:32:17.173: W/dalvikvm(12680): VFY: unable to resolve virtual method 2687: Landroid/view/ViewGroup;.setTranslationY (F)V
05-22 19:32:17.183: W/dalvikvm(12680): VFY: unable to resolve virtual method 5020: Lcom/actionbarsherlock/internal/widget/ActionBarView$HomeView;.onHoverEvent (Landroid/view/MotionEvent;)Z
05-22 19:32:17.183: W/dalvikvm(12680): VFY: unable to resolve virtual method 2881: Landroid/widget/FrameLayout;.onPopulateAccessibilityEvent (Landroid/view/accessibility/AccessibilityEvent;)V
05-22 19:32:17.223: W/dalvikvm(12680): VFY: unable to resolve virtual method 2893: Landroid/widget/HorizontalScrollView;.getAlpha ()F
05-22 19:32:17.223: W/dalvikvm(12680): VFY: unable to resolve virtual method 2894: Landroid/widget/HorizontalScrollView;.setAlpha (F)V
05-22 19:32:17.223: W/dalvikvm(12680): VFY: unable to resolve direct method 2924: Landroid/widget/LinearLayout;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;I)V
05-22 19:32:17.223: W/dalvikvm(12680): VFY: unable to resolve virtual method 2928: Landroid/widget/LinearLayout;.getAlpha ()F
05-22 19:32:17.223: W/dalvikvm(12680): VFY: unable to resolve virtual method 2931: Landroid/widget/LinearLayout;.getTranslationX ()F
05-22 19:32:17.223: W/dalvikvm(12680): VFY: unable to resolve virtual method 2938: Landroid/widget/LinearLayout;.setAlpha (F)V
05-22 19:32:17.223: W/dalvikvm(12680): VFY: unable to resolve virtual method 2944: Landroid/widget/LinearLayout;.setTranslationX (F)V
05-22 19:32:17.243: W/dalvikvm(12680): VFY: unable to resolve static field 2657 (ROOT) in Ljava/util/Locale;
05-22 19:32:17.303: W/dalvikvm(12680): VFY: unable to resolve virtual method 2592: Landroid/view/View;.jumpDrawablesToCurrentState ()V
05-22 19:32:21.583: W/dalvikvm(12680): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
05-22 19:32:21.593: E/AndroidRuntime(12680): FATAL EXCEPTION: main
05-22 19:32:21.593: E/AndroidRuntime(12680): java.lang.IllegalArgumentException: column '_id' does not exist
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.widget.CursorAdapter.init(CursorAdapter.java:174)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.widget.CursorAdapter.<init>(CursorAdapter.java:151)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:93)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:89)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at com.kinbit.abTest.Fragment1.onActivityCreated(Fragment1.java:66)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:891)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.os.Handler.handleCallback(Handler.java:587)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.os.Looper.loop(Looper.java:123)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at android.app.ActivityThread.main(ActivityThread.java:4627)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at java.lang.reflect.Method.invokeNative(Native Method)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at java.lang.reflect.Method.invoke(Method.java:521)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-22 19:32:21.593: E/AndroidRuntime(12680):    at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

3

で動作しているが動作してArrayAdapterいないSimpleCursorAdapter理由はSimpleCursorAdapter extends CursorAdapter、カーソルに。という名前の列が含まれていない場合は、が機能しないためCursorAdapter です_id。列の値は、_idにバインドされている値である必要がありますListView

このエラーは、互換性ライブラリとは何の関係もありません。

于 2012-05-22T23:02:59.900 に答える