lundi 6 juillet 2015

ZygoteInit$Method error in Fragment's onActivityCreated

I have a fragment, and I want to load up the listview in a particular way from my sql lite database:

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();
    }

}

Whenever I do this, It stalls on the first reference to the SQLLite Data. It says "com.android.internal.os.ZygoteInit$MethodAndArgsCaller" is the error. I've never gotten this before and I have no clue why this line would cause it since the activity is already created and started. What can I do to fix this?

Aucun commentaire:

Enregistrer un commentaire