0

I'm making an app for android. I need to insert a certain values to the database.

This is the method from the DatabaseHelper (using SQLite):

     public long insertMyAnime(MyList myList) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put("name", myList.getName());
        values.put("description", myList.getDescription());
        values.put("episodes", myList.getEpisodes());
        values.put("genre", myList.getGenre());
        values.put("rating", myList.getRating());
        values.put("episodesWatched", myList.getEpisodesWatched());
        values.put("stateId", myList.getStateId());

        long id = db.insert("myList", null, values);

        db.close();
        return id;
    }

And this is the the part I want to insert:

public void addAnime_onClick(View v){
    anime = domParser.getAnime(name);

    MyList myList = new MyList();

    myList.setName(anime.getName());
    myList.setDescription(anime.getDescription());
    myList.setEpisodes(anime.getEpisodes());
    myList.setGenre(anime.getGenre());
    myList.setEpisodesWatched(0);
    myList.setStateId(4);
    myList.setRating(0);

    db.insertMyAnime(myList);
}

And this is what the table looks like:

            //CREATE TABLE MYANIME
        String CREATE_TABLE_MYLIST = "CREATE TABLE myList (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "name TEXT," +
                "description TEXT," +
                "episodes INTEGER," +
                "genre TEXT," +
                "rating INTEGER," +
                "episodesWatched INTEGER," +
                "stateId INTEGER)";
        db.execSQL(CREATE_TABLE_MYLIST);

From the moment I press the button to insert, the app crashes.

Do you know what the problem could be? You would help me so much...

Dominickus
  • 17
  • 2

1 Answers1

0

Put this in your Code and take a look in your LogCat.

try {
  SQLiteDatabase db = this.getWritableDatabase();

  ContentValues values = new ContentValues();
  values.put("name", myList.getName());
  values.put("description", myList.getDescription());
  values.put("episodes", myList.getEpisodes());
  values.put("genre", myList.getGenre());
  values.put("rating", myList.getRating());
  values.put("episodesWatched", myList.getEpisodesWatched());
  values.put("stateId", myList.getStateId());

  long id = db.insert("myList", null, values);

  db.close();
  return id;           
} catch (SQLiteException e) {
  Log.e(TAG, "insert()", e);
}
EugZol
  • 6,476
  • 22
  • 41
Muhammed Misir
  • 400
  • 9
  • 22