java - Android SQLite ModernAsyncTask #1 -


i've built database schema , gone on specify methods query, update, add, , remove entries db, upon starting app modernasynctask error. read in android documentation not figure out how implement asynctask minimize memory leaks. log says exception occurring during doinbackground() have clue may going wrong here? love confirm can add data database, query it, update it, , remove it!

import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase.cursorfactory;  public class mydbhandler extends sqliteopenhelper {  private static final int database_version = 1; private static final string database_name = "contactsdb.db"; public static final string table_contacts = "contacts";  public static final string column_id = "_id"; public static final string column_name = "name"; public static final string column_phone = "phone"; public static final string column_status = "status"; public static final string column_blurb = "blurb";  public mydbhandler(context context, string name,                    cursorfactory factory, int version) {     super(context, database_name, factory, database_version);  }     @override     public void oncreate (sqlitedatabase db){         string create_contacts_table = "create table " +                 table_contacts + "("                 + column_id + " integer primary key," + column_name                 + " text," + column_phone + " integer,"                 + column_status + " text," + column_blurb                 + " text" + ")";         db.execsql(create_contacts_table);     }      @override     public void onupgrade (sqlitedatabase db,int oldversion, int newversion){         db.execsql("drop table if exists " + table_contacts);         oncreate(db);     } public void addcontact(contactsdb contacts) {      contentvalues values = new contentvalues();     values.put(column_name, contacts.getname());     values.put(column_phone, contacts.getphone());     values.put(column_status, contacts.getstatus());     values.put(column_blurb, contacts.getblurb());       sqlitedatabase db = this.getwritabledatabase();      db.insert(table_contacts, null, values);     db.close(); }  public contactsdb findcontact(string name) {     string query = "select * " + table_contacts + " " + column_name + " =  \"" + name + "\"";      sqlitedatabase db = this.getwritabledatabase();      cursor cursor = db.rawquery(query, null);      contactsdb contacts = new contactsdb();      if (cursor.movetofirst()) {         cursor.movetofirst();         contacts.setid(integer.parseint(cursor.getstring(0)));         contacts.setname(cursor.getstring(1));         contacts.setphone(integer.parseint(cursor.getstring(2)));         contacts.setstatus(cursor.getstring(3));         contacts.setblurb(cursor.getstring(4));         cursor.close();     } else {         contacts = null;     }     db.close();     return contacts; }  public void updatecontact(contactsdb contacts) {     sqlitedatabase db = this.getwritabledatabase();     contentvalues values = new contentvalues();      values.put(column_status, contacts.getstatus());     values.put(column_blurb, contacts.getblurb()); // row update, based on id      string selection = column_id + " ?";     string[] selectionargs = { string.valueof(contacts.getid()) };      int count = db.update(             table_contacts,             values,             selection,             selectionargs);     db.close(); }  public boolean deletecontact(string name) {      boolean result = false;      string query = "select * " + table_contacts + " " + column_name + " =  \"" + name + "\"";      sqlitedatabase db = this.getwritabledatabase();      cursor cursor = db.rawquery(query, null);      contactsdb contacts = new contactsdb();      if (cursor.movetofirst()) {         contacts.setid(integer.parseint(cursor.getstring(0)));         db.delete(table_contacts, column_id + " = ?",                 new string[] { string.valueof(contacts.getid()) });         cursor.close();         result = true;     }     db.close();     return result; }   } 

cheers , time!!

04-29 05:48:39.390    7446-7465/treehouse.greenlight e/androidruntime﹕ fatal exception: modernasynctask #1 process: treehouse.greenlight, pid: 7446 java.lang.runtimeexception: error occured while executing doinbackground()         @ android.support.v4.content.modernasynctask$3.done(modernasynctask.java:137)         @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355)         @ java.util.concurrent.futuretask.setexception(futuretask.java:222)         @ java.util.concurrent.futuretask.run(futuretask.java:242)         @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112)         @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587)         @ java.lang.thread.run(thread.java:811)  caused by: java.lang.illegalargumentexception: invalid column data1         @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:167)         @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:137)         @ android.content.contentproviderproxy.query(contentprovidernative.java:413)         @ android.content.contentresolver.query(contentresolver.java:475)         @ android.content.contentresolver.query(contentresolver.java:418)         @ android.support.v4.content.cursorloader.loadinbackground(cursorloader.java:49)         @ android.support.v4.content.cursorloader.loadinbackground(cursorloader.java:35)         @ android.support.v4.content.asynctaskloader.onloadinbackground(asynctaskloader.java:242)         @ android.support.v4.content.asynctaskloader$loadtask.doinbackground(asynctaskloader.java:51)         @ android.support.v4.content.asynctaskloader$loadtask.doinbackground(asynctaskloader.java:40)         @ android.support.v4.content.modernasynctask$2.call(modernasynctask.java:123)         @ java.util.concurrent.futuretask.run(futuretask.java:237) 

            at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112)             at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587)             at java.lang.thread.run(thread.java:811) 04-29 05:48:39.410 7446-7446/treehouse.greenlight e/viewrootimpl﹕ mispensupport: :false

you have more specific in question , show process sequence activity error. error not fault of database, beyond capacity of emulator or virtual machine. anyway checks configuration file , update eclipse these values:

--launcher.xxmaxpermsize 256m

--launcher.xxmaxpermsize 256m

-xms512m -xmx1024m


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -