1. AC Question's Avatar
    package com.example.android.pets;

    import android.content.ContentValues;
    import android.app.LoaderManager;
    import android.content.CursorLoader;
    import android.content.Loader;
    import android.content.Intent;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.ContactsContract;
    import android.support.design.widget.FloatingActionButton;
    import android.support.v7.app.AppCompatActivity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.ListView;
    import android.widget.Toast;

    import com.example.android.pets.data.PetContract;
    import com.example.android.pets.data.PetDbHelper;

    public class CatalogActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
    private static final int URI_LOADER = 0;
    private PetDbHelper mDbHelper;
    SQLiteDatabase db;
    ListView lvItems;
    PetCursorAdapter adapter;
    protected void onCreate(Bundle savedInstanceState) {
    lvItems = (ListView) findViewById(R.id.lstview);
    View emptyView = findViewById(R.id.empty_view);

    adapter = new PetCursorAdapter(this, null);

    // Setup FAB to open EditorActivity
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
    Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
    mDbHelper = new PetDbHelper(this);
    getLoaderManager().initLoader(URI_LOADER, null, this);


    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu options from the res/menu/menu_catalog.xml file.
    // This adds menu items to the app bar.
    getMenuInflater().inflate(R.menu.menu_catalog, menu);
    return true;

    public boolean onOptionsItemSelected(MenuItem item) {
    // User clicked on a menu option in the app bar overflow menu
    switch (item.getItemId()) {
    // Respond to a click on the "Insert dummy data" menu option
    case R.id.action_insert_dummy_data:
    return true;
    // Respond to a click on the "Delete all entries" menu option
    case R.id.action_delete_all_entries:
    // Do nothing for now
    return true;
    return super.onOptionsItemSelected(item);

    private void insertdummy() {
    ContentValues values=new ContentValues();
    values.put(PetContract.PetEntry.COLUMN_PET_NAME, "toto");
    values.put(PetContract.PetEntry.COLUMN_PET_GENDER, PetContract.PetEntry.GENDER_MALE);
    values.put(PetContract.PetEntry.COLUMN_PET_WEIGHT, 7);
    Uri URI_ID= getContentResolver().insert(PetContract.PetEntry.CONTENT_URI, values);
    Toast.makeText(getApplicationContext(), R.string.fail_save,Toast.LENGTH_LONG).show();
    Toast.makeText(getApplicationContext(), R.string.success_save, Toast.LENGTH_LONG).show();


    public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    String[] projection = {PetContract.PetEntry._ID,
    String selection = null;
    String selectionArgs[] =null;
    return new CursorLoader(getApplicationContext(), ContactsContract.Data.CONTENT_URI,
    projection, selection, selectionArgs, null);

    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    public void onLoaderReset(Loader<Cursor> loader) {

    The app is crashes when first lanuched and give me those error when using the CursorLoaders callback methods, I didn't know the line of code that makes the app crashes but I think the imports has a hand on it, please help?

    github.com/NayirMicheal/petsapp this is the link to the entire app on github, this app creating database of pets and saving those pets into database and retriving them back from database and displaying the data retrieved into listview throught CursorLoader

    drive.google.com/open?id=0Bx6oqNfteEuOUjQ4Vnc1bF9xcVk full logcat
    03-29-2017 07:44 PM

Similar Threads

  1. Replies: 1
    Last Post: 03-29-2017, 08:26 PM
  2. Is Samsung giving Note 7 customers any discounts on the S8 or the Note 8?
    By AC Question in forum Samsung Galaxy S8 & S8+
    Replies: 2
    Last Post: 03-29-2017, 08:20 PM
  3. Replies: 0
    Last Post: 03-29-2017, 07:40 PM
  4. Replies: 0
    Last Post: 03-29-2017, 07:11 PM
  5. can I remove a widget without uninstalling the app?
    By AC Question in forum Ask a Question
    Replies: 1
    Last Post: 03-29-2017, 07:05 PM