android - sqlite database reading error -



android - sqlite database reading error -

hi reading info database created using sqlite manager , copied info folder of application cursor returning 0 when tried print getcount wrong in code below code error

unable start activity

componentinfo{your.pckage.namespac/your.pckage.namespac.tabaractivity},second error

caused by: java.lang.nullpointerexception

public class dbhelper { public static final string key_rowid = "id"; public static final string key_name = "name"; public static final string little = "small"; public static final string big = "large"; public static final string type1 = "type1"; public static final string type2 = "type2"; public static final string type3 = "type3"; public static final string tex = "tex"; public static final string origin = "origin"; public static final string description = "description"; public static final string bookmark = "bookmark"; public static final string key_email = "email"; private static final string tag = "dbadapter"; private static final string database_name = "vegetable.db"; private static final string database_table = "mac"; private static final int database_version = 2; private static final string database_create ="create table mac (id integer primary key autoincrement not null ,"+ "name varchar, little integer,"+ "large integer, type1 integer,"+ "type2 integer, type3 integer,"+ "tex varchar, origin varchar,"+ "description varchar, bookmark varchar);"; private final context context; private databasehelper dbhelper; private sqlitedatabase db; public dbhelper(context ctx) { this.context = ctx; dbhelper = new databasehelper(context); } private static class databasehelper extends sqliteopenhelper { databasehelper(context context) { super(context, database_name, null, database_version); } @override public void oncreate(sqlitedatabase db) { seek { db.execsql(database_create); } grab (sqlexception e) { e.printstacktrace(); } } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { log.w(tag, "upgrading database version " + oldversion + " " + newversion + ", destroy old data"); db.execsql("drop table if exists contacts"); oncreate(db); } } //---opens database--- public dbhelper open() throws sqlexception { //db = dbhelper.getwritabledatabase(); db=dbhelper.getreadabledatabase(); homecoming this; } //---closes database--- public void close() { dbhelper.close(); } //---deletes particular contact--- public boolean deletecontact(long rowid) { homecoming db.delete(database_table, key_rowid + "=" + rowid, null) > 0; } //---retrieves contacts--- public cursor getallcontacts() { homecoming db.query(database_table, new string[] {key_rowid, key_name, small,large,type1,type2,type3,tex,origin,description,bookmark}, null, null, null, null, null); } //---retrieves particular contact--- public cursor getcontact(long rowid) throws sqlexception { cursor mcursor = db.query(true, database_table, new string[] {key_rowid, small,large,type1,type2,type3, texture,origin,description,bookmark}, key_rowid + "=" + rowid, null, null, null, null, null); system.out.println(mcursor); if (mcursor != null) { system.out.println(1); //boolean t=mcursor.movetofirst(); boolean t=mcursor.movetonext(); system.out.println(t); } homecoming mcursor; } //---updates contact--- public boolean updatecontact(long rowid, string secondview) { contentvalues args = new contentvalues(); args.put(key_name, secondview); homecoming db.update(database_table, args, key_rowid + "=" + rowid, null) > 0; } } public class mylistactivity extends activitygroup { /** called when activity first created. */ string tag = "events"; string[] presidents; string[] ima; int i=0; intent intent; integer[] imageids= {r.drawable.abbaysmall,r.drawable.edalesmall}; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.listtype); seek { string destpath = "/data/data/" + getpackagename() + "/databases/vegetable.db"; file f = new file(destpath); if (!f.exists()) { copydb( getbasecontext().getassets().open("vegetable.db"), new fileoutputstream(destpath)); system.out.println("hi"); } } grab (filenotfoundexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } dbhelper db = new dbhelper(this); //---get contact--- db.open(); cursor c = db.getcontact(1); system.out.println(c.getcount()); if (c.movetofirst()){ }else { toast.maketext(this, "no contact found", toast.length_long).show(); db.close(); } list.setadapter(adapter); //setlistadapter(adapter); list.setonitemclicklistener(onlistclick); } public void copydb(inputstream inputstream, outputstream outputstream) throws ioexception { //---copy 1k bytes @ time--- byte[] buffer = new byte[1024]; int length; while ((length = inputstream.read(buffer)) > 0) { outputstream.write(buffer, 0, length); } inputstream.close(); outputstream.close(); } }

does these code print message?(in getcontact method),is mcursor null?

if (mcursor != null) { system.out.println(1); //boolean t=mcursor.movetofirst(); boolean t=mcursor.movetonext(); system.out.println(t); }

edit:try this? load image info scheme contentprovider

private final uri photo_uri = mediastore.images.media.external_content_uri; private final string[] photo_pjt = new string[] { mediastore.images.media._id, mediastore.images.media.data, mediastore.images.media.date_taken, mediastore.images.media.size, mediastore.images.media.description, mediastore.images.media.title, mediastore.images.media.mime_type }; contentresolver mresolver = mcontext.getcontentresolver(); cursor c = mresolver.query(photo_uri, photo_pjt, null, null, titlesearc);

android android-layout android-intent

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -