gpt4 book ai didi

android - ListFragment 因兼容库而崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 09:07:40 25 4
gpt4 key购买 nike

我正在使用针对 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 一起工作。我什至将标志添加到构造函数中。当我实例化这个 fragment 时,设备说应用程序已被中断并关闭它。有人知道我做错了什么吗?

提前致谢。


编辑。这是来自 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)

最佳答案

它与 ArrayAdapter 一起工作而不与 SimpleCursorAdapter 一起工作的原因是因为 SimpleCursorAdapter 扩展了 CursorAdapter,而 CursorAdapter 如果您的光标不包含名为 _id 的列,将不起作用_id 列中的值应该是绑定(bind)到 ListView 的值。

此错误与兼容性库无关。

关于android - ListFragment 因兼容库而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10711272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com