java - Add bitmap to sql database errors? -
so in android app user can take picture hits done , image decompiled byte array , added sql database. getting crash when try image sql , error.
here logcat:
10-02 20:30:56.543 6259-6259/com.nick.mowen.receiptmanager e/cursorwindow: failed read row 0, column 0 cursorwindow has 0 rows, 2 columns. 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: fatal exception: main 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: process: com.nick.mowen.receiptmanager, pid: 6259 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: java.lang.illegalstateexception: couldn't read row 0, col 0 cursorwindow. make sure cursor initialized correctly before accessing data it. 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: @ android.database.cursorwindow.nativegetlong(native method) 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: @ android.database.cursorwindow.getlong(cursorwindow.java:524) 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: @ android.database.abstractwindowedcursor.getlong(abstractwindowedcursor.java:75) 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: @ android.database.abstractcursor.movetoposition(abstractcursor.java:220) 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: @ com.nick.mowen.receiptmanager.managerdatabaseadapter.getimageatposition(managerdatabaseadapter.java:90) 10-02 20:30:56.553 6259-6259/com.nick.mowen.receiptmanager e/androidruntime: @ com.nick.mowen.receiptmanager.mainactivity.itemclicked(mainactivity.java:115)
here database:
public class managerdatabaseadapter{ managerhelper helper; context mcontext; public managerdatabaseadapter(context context) { helper = new managerhelper(context); } public string getalldata () { string[] columns = {managerhelper.uid,managerhelper.name,managerhelper.code,managerhelper.address}; sqlitedatabase db = helper.getwritabledatabase(); cursor cursor = db.query(managerhelper.table_name, columns, null, null, null, null, null); stringbuffer buffer = new stringbuffer(); while (cursor.movetonext()){ int cid = cursor.getint(0); string name = cursor.getstring(1); string code = cursor.getstring(2); string adress = cursor.getstring(3); buffer.append(cid+" "+name+" "+code+" "+adress+"/n"); } db.close(); cursor.close(); return buffer.tostring(); } public string[] getdataarray(string name) { string[] columns = {managerhelper.name,managerhelper.address}; sqlitedatabase db = helper.getwritabledatabase(); cursor cursor = db.query(managerhelper.table_name, columns, managerhelper.name + " = '" + name + "'", null, null, null, null); string[] data = new string[3]; cursor.movetofirst(); int index1 = cursor.getcolumnindex(managerhelper.name); int index3 = cursor.getcolumnindex(managerhelper.address); data[0] = cursor.getstring(index1); data[2] = cursor.getstring(index3); db.close(); cursor.close(); return data; } public byte[] getdatabytearray(string name) { string[] columns = {managerhelper.code}; sqlitedatabase db = helper.getwritabledatabase(); cursor cursor = db.query(managerhelper.table_name, columns, managerhelper.name + " = '" + name + "'", null, null, null, null); byte[] data; int index = cursor.getcolumnindex(managerhelper.code); data = cursor.getblob(index); db.close(); return data; } public string[] getdataatposition(int position) { string[] columns = {managerhelper.uid,managerhelper.name,managerhelper.address}; sqlitedatabase db = helper.getwritabledatabase(); cursor cursor = db.query(managerhelper.table_name, columns, null, null, null, null, null); cursor.movetoposition(cursor.getcount() - position - 1); string[] data = new string[2]; int index1 = cursor.getcolumnindex(managerhelper.name); int index3 = cursor.getcolumnindex(managerhelper.address); data[0] = cursor.getstring(index1); data[1] = cursor.getstring(index3); db.close(); cursor.close(); return data; } public byte[] getimageatposition(int position) { string[] columns = {managerhelper.uid,managerhelper.code}; sqlitedatabase db = helper.getwritabledatabase(); cursor cursor = db.query(managerhelper.table_name, columns, null, null, null, null, null); cursor.movetoposition(cursor.getcount() - position - 1); int index = cursor.getcolumnindex(managerhelper.code); byte[] data = cursor.getblob(index); db.close(); cursor.close(); return data; } public long insertdata(string name, byte[] image, string address) { sqlitedatabase db = helper.getwritabledatabase(); contentvalues contentvalues = new contentvalues(); contentvalues.put(managerhelper.name, name); contentvalues.put(managerhelper.code, image); contentvalues.put(managerhelper.address, address); long id = db.insert(managerhelper.table_name, null, contentvalues); db.close(); return id; } public int updateplace(string oldname, string newname) { sqlitedatabase db = helper.getwritabledatabase(); contentvalues contentvalues = new contentvalues(); contentvalues.put(managerhelper.name, newname); string[] whereargs= {oldname}; int count = db.update(managerhelper.table_name, contentvalues, managerhelper.name + " =?", whereargs); db.close(); return count; } public long deleterow(string delete) { sqlitedatabase db = helper.getwritabledatabase(); string[] whereargs = {delete}; long id = db.delete(managerhelper.table_name, managerhelper.name + " =?", whereargs); db.close(); return id; } public list<maininfo> getnamearraylist() { string[] columns = {managerhelper.uid,managerhelper.name,managerhelper.address}; sqlitedatabase db = helper.getwritabledatabase(); cursor cursor = db.query(managerhelper.table_name, columns, null, null, null, null, null); list<maininfo> names = new arraylist<>(); int index1 = cursor.getcolumnindex(managerhelper.name); int index3 = cursor.getcolumnindex(managerhelper.address); while (cursor.movetonext()) { maininfo current = new maininfo(); current.title = cursor.getstring(index1); current.address = cursor.getstring(index3); names.add(cursor.getcolumnindex(managerhelper.uid), current); } cursor.close(); db.close(); return names; } static class managerhelper extends sqliteopenhelper { private static final string extra_message = "com.nick.mowen.receiptmanager.location"; private static final string database_name = "main_data"; private static final string table_name = "data"; private static final int version = 2; private static final string uid = "_id"; private static final string name = "codes"; private static final string code = "code"; private static final string address = "address"; private static final string create_table = "create table "+table_name+" ("+uid+" integer primary key autoincrement, "+name+" varchar(255), "+code+" blob,"+address+" varchar(255));"; private static final string drop_table = "drop_table if exists"+table_name; private context context; public managerhelper(context context) { super(context, database_name, null, version); this.context=context; } @override public void oncreate(sqlitedatabase db) { intent intent = new intent(context,codeadder.class); intent.putextra(extra_message, true); context.startactivity(intent); try { db.execsql(create_table); } catch (sqlexception e) { } } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { try { db.execsql(drop_table); oncreate(db); }catch (sqlexception e){ } } } }
Comments
Post a Comment