samedi 27 juin 2015

Error when trying to get data from SQLite databace

i am using CursorLoader to get some data from my database, that was putted into database before, but i got next error:

android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0

database are not empty!

here is my fragment's code:

public class FriendsFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>{

    public final static String[] COUNTERS_COLUMNS = {
            UserFriendsEntry._ID,
    };

    public final static int C_COUNTERS_FRIEND_ID = 0;

    public FriendsFragment() {
    }

    @InjectView(R.id.viewpager_friends) ViewPager mViewPager;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_friends, container, false);
        ButterKnife.inject(this, rootView);

        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        getLoaderManager().initLoader(0, null, this);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        return new CursorLoader(
                getActivity(),
                UserFriendsEntry.CONTENT_URI,
                FriendsFragment.COUNTERS_COLUMNS,
                null,
                null,
                null);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        if (data != null){
            int columnsCount = data.getCount();
            int col = data.getInt(C_COUNTERS_FRIEND_ID);
        }
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
    }

Any help!!!

why it happens and how to fix it? GREAT THANKS!

Aucun commentaire:

Enregistrer un commentaire