SQLite not loading data upon activity starting in android -
problem: user matched user, , game begins. user given words, taken sqlite database. problem is, when activity starts, area words should empty. log not show errors. here relevant code.
the database class words kept:
public class wordslistdatabasehelper extends sqliteopenhelper { protected static set<string> mselectedwords; private static final string db_name = "game_table"; private static final int db_version = 1; protected static linkedlist<string> mcopy; public static int gamenumber = 0; wordslistdatabasehelper(context context) { super(context, db_name, null, db_version); } @override public void oncreate(sqlitedatabase db) { db.execsql("create table game (" + "_id integer primary key autoincrement, " + "selected_words text, " + "game_number integer);" ); collection<string> wordlist = new linkedlist<string>(); mselectedwords = new linkedhashset<string>(); wordlist.add("ant"); wordlist.add("almond"); //lots more words mcopy = new linkedlist<string>(wordlist); gson gson = new gson(); string wordscontainer = gson.tojson(mcopy); insertwordlist(db, wordscontainer, gamenumber); } private static void insertwordlist(sqlitedatabase db, string wordscontainer, int gamenumber) { contentvalues wordvalues = new contentvalues(); gson gson = new gson(); collections.shuffle(mcopy); mselectedwords.addall(mcopy.sublist(1,7)); wordscontainer = gson.tojson(mselectedwords); wordvalues.put("selected_words", wordscontainer); wordvalues.put("game_number", gamenumber); db.insert("game", null, wordvalues); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { }
}
here relevant code findingopponentsactivity, randomly matches user opponent. when match created, user taken startgameactivity.
intent intentrand = new intent(findingopponentactivity.this, startgameactivity. .class); int gamenum = wordslistdatabasehelper.gamenumber; intentrand.putextra( startgameactivity.extra_rand_opponent, mopponent.getobjectid()); intentrand.putextra( startgameactivity.extra_game_number, gamenum); sendpushnotification(); startactivity(intentrand); }
and now, code in oncreate() method of startgameactivity:
intent intent = getintent(); mgamenum = intent.getintextra(extra_game_number, 0); //create cursor try { sqliteopenhelper wordslistdatabasehelper = new wordslistdatabasehelper(this); sqlitedatabase db = wordslistdatabasehelper.getreadabledatabase(); cursor cursor = db.query("game", new string[] {"selected_words"}, "game_number =? ", new string[]{integer.tostring(mgamenum)}, null, null, null); //move first record in cursor if (cursor.movetofirst()) { //get wordlist string savedwordlist = cursor.getstring(0); gson gson = new gson(); type type = new typetoken<arraylist<string>>() {}.gettype(); arraylist<string> finalwordlist = gson.fromjson(savedwordlist, type); mcopy = new linkedlist<string>(); mcopy.addall(finalwordlist); word1 = (textview) findviewbyid(r.id.word1); word1.settext(mcopy.get(1)); word2 = (textview) findviewbyid(r.id.word2); word2.settext(mcopy.get(2));
please let me know if there more code need post.
edit forgot mention getting log registering error message:
09-29 13:48:42.572 13689-13720/? e/sqlitelog﹕ (1) no such table: mmsconfig
i checked on , on again problem, unable find going wrong.
this problem has been solved; re-installed app, cleaned project , synced gradle.
Comments
Post a Comment