android - App Crashing Upon Saving Update -


i'm having issues app creating, problem arises when click save button when updating record.

here java file.

import com.androidadvance.db.databasehelper; import android.app.activity; import android.content.intent; import android.os.bundle; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.toast;  public class addupdatevalues extends activity implements onclicklistener {     private button btn_updaterecord;     private edittext txtpname, txtpprice;     databasehelper db;     productmodel pm;     intent i;      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.addupdatevalues);          = getintent();          txtpname = (edittext) findviewbyid(r.id.txt_udatepname);         txtpprice = (edittext) findviewbyid(r.id.txt_udatepprice);          txtpname.settext(i.getextras().getstring("name"));         txtpprice.settext(i.getextras().getstring("price"));         btn_updaterecord = (button) findviewbyid(r.id.btn_updaterecord);         btn_updaterecord.setonclicklistener(this);     }      @override     public void onclick(view v) {         // todo auto-generated method stub         switch (v.getid()) {         case r.id.btn_updaterecord:             if (txtpname.gettext().tostring().equals("")                     || txtpprice.gettext().tostring().equals("")) {                 toast.maketext(addupdatevalues.this, "please add values..",                         toast.length_long).show();             } else {                  db = new databasehelper(getapplicationcontext());                 db.getwritabledatabase();                 pm = new productmodel();                 pm.productname = txtpname.gettext().tostring();                 pm.productprice = txtpprice.gettext().tostring();                 pm.idno = i.getextras().getstring("id");                  log.i(">>>>>productid<<<<<", "" + i.getextras().getstring("id"));                 db.updateproduct(pm);                 toast.maketext(addupdatevalues.this,                         "room update successfully.", toast.length_long).show();                  db.close();                 super.onresume();              }             break;         }      }  } 

here xml file

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical"     android:background="@drawable/background" >      <textview         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_marginleft="5dp"         android:text="update room length:" />      <edittext         android:id="@+id/txt_udatepname"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_margin="5dp"         android:hint="room length" />      <textview         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_marginleft="5dp"         android:text="update room width:" />      <edittext         android:id="@+id/txt_udatepprice"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_margin="5dp"         android:hint="room width" />      <button         android:id="@+id/btn_updaterecord"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:text="save changes" />  </linearlayout> 

databasehelper

import java.util.arraylist; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import com.homediyassistant.screen.productmodel;  public class databasehelper extends sqliteopenhelper {      public static string databasename = "androidadvancesqlite";     public static string producttable = "products";     public static string colproductid = "id";     public static string _colproductid = "productidno";     public static string colproductname = "productname";     public static string colproductprice = "productprice";     private arraylist<productmodel> cartlist = new arraylist<productmodel>();     context c;      public databasehelper(context context) {         super(context, databasename, null, 33);         c = context;     }      @override     public void oncreate(sqlitedatabase db) {         // db.execsql("create table if not exists " + producttable + "("         // + colproductid + " integer primary key autoincrement , "         // + "productidno" + "text," + colproductname + " text ,"         // + colproductprice + " text)");          db.execsql("create table if not exists producttable(id integer primary key autoincrement,"                 + "productidno"                 + " text ,"                 + "productname"                 + " text,"                 + "productprice" + " text)");      }      @override     public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {         db.execsql("drop table if exists" + producttable);         oncreate(db);     }      public void addproduct(productmodel productitem) {         sqlitedatabase db = this.getwritabledatabase();         contentvalues contentvalues = new contentvalues();         contentvalues.put("productidno", productitem.idno);         contentvalues.put("productname", productitem.productname);         contentvalues.put("productprice", productitem.productprice);         db.insert("producttable", null, contentvalues);         db.close();      }      // update      public void updateproduct(productmodel productlist) {         sqlitedatabase db = this.getwritabledatabase();         contentvalues contentvalues = new contentvalues();         contentvalues.put("productname", productlist.productname);          contentvalues.put("productprice", productlist.productprice);         db.update("producttable", contentvalues, "productidno="                 + productlist.idno, null);          db.close();     }      public void emptyproduct() {         try {             sqlitedatabase db = this.getwritabledatabase();             db.execsql("delete producttable");             db.close();         } catch (exception e) {             e.printstacktrace();         }     }      public void removeproduct(string productid, string pname, string pprice) {         try {             // sqlitedatabase db = this.getwritabledatabase();             // db.execsql("delete producttable productidno="             // + productid);             // db.close();              string[] args = { productid };             getwritabledatabase().delete("producttable", "productidno=?", args);          } catch (exception e) {             e.printstacktrace();         }     }      public arraylist<productmodel> getproudcts() {          cartlist.clear();          sqlitedatabase db = this.getwritabledatabase();         cursor cursor = db.rawquery("select * producttable", null);         if (cursor.getcount() != 0) {             if (cursor.movetofirst()) {                 {                     productmodel item = new productmodel();                      item.idno = cursor.getstring(cursor                             .getcolumnindex("productidno"));                      item.productname = cursor.getstring(cursor                             .getcolumnindex("productname"));                      item.productprice = cursor.getstring(cursor                             .getcolumnindex("productprice"));                      cartlist.add(item);                  } while (cursor.movetonext());             }         }         cursor.close();         db.close();         return cartlist;     } } 

here logcat

05-03 12:10:09.323: e/sensormanager(3963): thread start 05-03 12:10:09.898: e/spannablestringbuilder(3963): span_exclusive_exclusive spans cannot have 0 length 05-03 12:10:09.898: e/spannablestringbuilder(3963): span_exclusive_exclusive spans cannot have 0 length 05-03 12:10:17.498: e/spannablestringbuilder(3963): span_exclusive_exclusive spans cannot have 0 length 05-03 12:10:17.498: e/spannablestringbuilder(3963): span_exclusive_exclusive spans cannot have 0 length 05-03 12:10:20.868: e/spannablestringbuilder(3963): span_exclusive_exclusive spans cannot have 0 length 05-03 12:10:20.868: e/spannablestringbuilder(3963): span_exclusive_exclusive spans cannot have 0 length 05-03 12:10:38.173: e/sqlitelog(3963): (1) no such column: fff 05-03 12:10:38.193: e/androidruntime(3963): fatal exception: main 05-03 12:10:38.193: e/androidruntime(3963): android.database.sqlite.sqliteexception: no such column: fff (code 1): , while compiling: update producttable set productprice=?,productname=? productidno=fff 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:1038) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:649) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:58) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqlitestatement.<init>(sqlitestatement.java:31) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqlitedatabase.updatewithonconflict(sqlitedatabase.java:1563) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.database.sqlite.sqlitedatabase.update(sqlitedatabase.java:1514) 05-03 12:10:38.193: e/androidruntime(3963):     @ com.homediyassistant.db.databasehelper.updateproduct(databasehelper.java:68) 05-03 12:10:38.193: e/androidruntime(3963):     @ com.homediyassistant.screen.addupdatevalues.onclick(addupdatevalues.java:59) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.view.view.performclick(view.java:4261) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.view.view$performclick.run(view.java:17356) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.os.handler.handlecallback(handler.java:615) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.os.handler.dispatchmessage(handler.java:92) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.os.looper.loop(looper.java:137) 05-03 12:10:38.193: e/androidruntime(3963):     @ android.app.activitythread.main(activitythread.java:4921) 05-03 12:10:38.193: e/androidruntime(3963):     @ java.lang.reflect.method.invokenative(native method) 05-03 12:10:38.193: e/androidruntime(3963):     @ java.lang.reflect.method.invoke(method.java:511) 05-03 12:10:38.193: e/androidruntime(3963):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) 05-03 12:10:38.193: e/androidruntime(3963):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) 05-03 12:10:38.193: e/androidruntime(3963):     @ dalvik.system.nativestart.main(native method) 

i cannot put finger on falling down.

your appreciated.

thanks

looking @ logcat seems app getting crashed because entering 'id' (productidno), not exist in table. either enter valid 'id' or check 'id' being entered.

i hope solves problem.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -