片段的onActivityCreated中的ZygoteInit $ Method错误

时间:2015-07-06 20:48:51

标签: android sqlite android-fragments

我有一个片段,我想从我的sql lite数据库中以特定方式加载listview:

private ProductDbAdapter mDbHelper;
private ProductListAdapter productAdapter;
private View mView;

 @Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Open Database Connection
    mDbHelper = new ProductDbAdapter(getActivity());


    try {
        mDbHelper.open();
    } catch (SQLException e) {
        e.printStackTrace();
    }


    // Setup list view
    productAdapter = new ProductListAdapter(getActivity(), R.layout.product_row);
    ListView lv = (ListView) mView.findViewById(R.id.lvProducts);
    lv.setAdapter(productAdapter);

    Cursor productCursor = mDbHelper.fetchAll();
    getActivity().startManagingCursor(productCursor);

    int numProducts = productCursor.getCount();
    for(int i =0; i< numProducts; i++) {
        Product prdt = new Product();
        // The line below is where it throws an exception //
        prdt.Name = productCursor.getString(productCursor.getColumnIndexOrThrow(ProductDbAdapter.KEY_NAME));
        prdt.type = productCursor.getString(productCursor.getColumnIndexOrThrow(ProductDbAdapter.KEY_TYPE));
        String strDate = productCursor.getString(productCursor.getColumnIndexOrThrow(ProductDbAdapter.KEY_EXPDATE));

        // format into local date/time format
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        try {
            prdt.dateExpires = sdf.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        // Add to custom adapter
        productAdapter.add(prdt);
        productCursor.moveToNext();
    }

}

每当我这样做时,它就会停止对SQLLite数据的第一次引用。它说“com.android.internal.os.ZygoteInit $ MethodAndArgsCaller”是错误。我以前从来没有得过这个,我不知道为什么这条线会导致它,因为活动已经创建并开始了。我该怎么做才能解决这个问题?

0 个答案:

没有答案