mysql - ANDROID STUDIO: Gradle does not build sql database -


i have program use sql store users credit. used work fine until 1 faithful day stopped running. here problem first occurs.

package com.inc.nicky.tapit;  mydbhandler dbhandler = new mydbhandler(this, null, null, 1);      product product =             dbhandler.findproduct("coins");     eee=(textview)findviewbyid(r.id.someid);     if (product != null) {          eee.settext(product.getquantity());       } else {     product =             new product("coins", 0);      dbhandler.addproduct(product);     eee.settext("0");     } 

logcat says cannot change text product.getquantity(). if remove line , future usage of sql problem still remains; cannot call product.getquantity() when not changing texts.

here more detailed report of error:

unable start activity componentinfo{com.inc.nicky.tapit/com.inc.nicky.tapit.mainactivity}: android.content.res.resources$notfoundexception: string resource id #0x0         @ android.app.activitythread.performlaunchactivity(activitythread.java:2394)         @ android.app.activitythread.handlelaunchactivity(activitythread.java:2452)         @ android.app.activitythread.access$900(activitythread.java:172)         @ android.app.activitythread$h.handlemessage(activitythread.java:1302)         @ android.os.handler.dispatchmessage(handler.java:102)         @ android.os.looper.loop(looper.java:136)         @ android.app.activitythread.main(activitythread.java:5586)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:515)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1268)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1084)         @ dalvik.system.nativestart.main(native method)  caused by: android.content.res.resources$notfoundexception: string resource id #0x0         @ android.content.res.resources.gettext(resources.java:1408)         @ android.widget.textview.settext(textview.java:4949)         @ com.inc.nicky.tapit.mainactivity.lookupproduct(mainactivity.java:42)         @ com.inc.nicky.tapit.mainactivity.oncreate(mainactivity.java:78)         @ android.app.activity.performcreate(activity.java:5451)         @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1093)         @ android.app.activitythread.performlaunchactivity(activitythread.java:2358) 

           

here mydbhandler:

public class mydbhandler extends sqliteopenhelper {      private static final int database_version = 2;     private static final string database_name = "gamedb.db";     private static final string table_products = "products";      public static final string column_id = "_id";     public static final string column_productname = "productname";     public static final string column_quantity = "quantity";      public mydbhandler(context context, string name, sqlitedatabase.cursorfactory factory, int version) {         super(context, database_name, factory, database_version);     }       @override     public void oncreate(sqlitedatabase db) {         string create_products_table = "create table " +         table_products + "("         + column_id + " integer primary key autoincrement," + column_productname         + " text," + column_quantity + " integer" + ")";         db.execsql(create_products_table);     }      @override     public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {         db.execsql("drop table if exists " + table_products);         oncreate(db);     }      public void addproduct(product product) {         contentvalues values = new contentvalues();         values.put(column_productname, product.getproductname());         values.put(column_quantity, product.getquantity());          sqlitedatabase db = this.getwritabledatabase();          db.insert(table_products, null, values);         db.close();     }      public product findproduct(string productname) {     string query = "select * " + table_products + " " + column_productname + " =  \"" + productname + "\"";          sqlitedatabase db = this.getwritabledatabase();          cursor cursor = db.rawquery(query, null);          product product = new product();          if (cursor.movetofirst()) {             cursor.movetofirst();             product.setid(integer.parseint(cursor.getstring(0)));             product.setproductname(cursor.getstring(1));             product.setquantity(integer.parseint(cursor.getstring(2)));             cursor.close();         } else {             product = null;         }          db.close();         return product;     }      public boolean deleteproduct(string productname) {          boolean result = false;          string query = "delete " + table_products + " " + column_productname + " =  \"" + productname + "\"";          sqlitedatabase db = this.getwritabledatabase();          db.execsql(query);         db.close();         return result;     } } 

and product class:

public class product {      private int _id;     private string _productname;     private int _quantity;      public product() {}      public product(int id, string productname, int quantity) {         this._id = id;         this._productname = productname;         this._quantity = quantity;     }      public product(string productname, int quantity) {         this._productname = productname;         this._quantity = quantity;     }      public void setid(int id) {         this._id = id;     }      public int getid() {         return this._id;     }      public void setproductname(string productname) {         this._productname = productname;     }      public string getproductname() {         return this._productname;     }      public void setquantity(int quantity) {         this._quantity = quantity;     }      public int getquantity() {         return this._quantity;     }  } 

what doing before bug?

  1. i imported facebook sdk , ran application couple of times - fine
  2. i changed icon of application , debug/androidmanifest appeared, covered in red text saying: not allowed here, not allowed there. ever since sql not working, although working fine

settext(int) expects int id of string resource. getquantity() not returning id of string resource. hence, settext(int) crash resourcenotfoundexception.

replace:

eee.settext(product.getquantity()); 

with:

eee.settext(integer.tostring(product.getquantity())); 

this call settext(string) string representation of int returned getquantity().


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -