0
問題:用戶與其他用戶相匹配,遊戲開始。給用戶一些單詞,這些單詞來自SQLite數據庫。問題是,當活動開始時,單詞應該是空的區域。該日誌不顯示任何錯誤。這是相關的代碼。SQLite無法在android中啓動活動時加載數據
數據庫類,所有的字被保持:
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) {
}
}
下面是從FindingOpponentsActivity,其隨機地與對手的用戶匹配的相關代碼。當匹配被創建時,用戶將被帶到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);
}
而現在,這是StartGameActivity的onCreate()方法的代碼:
Intent intent = getIntent();
mGameNum = intent.getIntExtra(EXTRA_GAME_NUMBER, 0);
//create a 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 to the first record in the 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));
請讓我知道如果有任何更多的代碼,我需要發佈。
編輯我忘了提,我得到日誌已註冊此錯誤消息:
09-29 13:48:42.572 13689-13720/? E/SQLiteLog﹕ (1) no such table: mmsconfig
我檢查了一遍又一遍的問題,但我無法找到我在哪裏出錯了。
這些都不是來自你的應用程序的日誌 – njzk2
你是什麼意思?我從logcat中得到了這個消息。 – Frosty619
該消息是關於'mmsconfig'的。你在使用一個名爲'mmsconfig'的表嗎?另外,您簡要發佈的其他消息提及了谷歌應用和提供商的包名 – njzk2