My android app contains two table in a database where one table stores an dynamic data and another table should store nearly 7000 dictionary words into that table by parsing an text file.This action should be done one time when app installs first time.Text file is stored in raw folder.
The problem i am facing here is, when i try to parse and store into that table logcat say no such table in the database.
Here is the method and DBHelper snippet code:
DBHelper class snippet:
private static final String DICTIONARY_TABLE_CREATE =
"CREATE TABLE " + DATABASE_TABLE_NAME_DICTIONARY + "(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT,"+
"words TEXT NOT NULL);";
private static final String USER_TABLE_CREATE =
"CREATE TABLE " + DATABASE_TABLE_NAME_USERINFO + "(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT,"+
"player_name TEXT NOT NULL, " +
"player_username TEXT NOT NULL, " +
"player_pass TEXT NOT NULL, " +
"player_played VARCHAR NOT NULL, " +
"player_won VARCHAR NOT NULL, " +
"player_loss VARCHAR NOT NULL);";
public void onCreate(SQLiteDatabase db)
{
try
{
db.execSQL(USER_TABLE_CREATE);
db.execSQL(DICTIONARY_TABLE_CREATE);
System.out.println("In onCreate");
}
catch(Exception e)
{
e.printStackTrace();
}
}
Here is method to parse text file and insert values into database:
public void CopytxtfileTodb()
{
InputStream inputStream = getResources().openRawResource(R.raw.wordslists);
BufferedReader br = new BufferedReader( new InputStreamReader(inputStream));
SQLiteDatabase db = playerDB.getWritableDatabase();
try
{
String line = "";
while((line= br.readLine()) != "")
{
ContentValues values = new ContentValues();
values.put("words", line);
try
{
db.insert(DBHelper.DATABASE_TABLE_NAME_DICTIONARY, null, values);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
catch(Exception e)
{
System.err.println("Parse Error: " + e.getMessage());
}
The problem might be because DbHelper is not instantiated properly.Check if proper database name, version and context are passed during the instantiation of dbhelper.
-Also can you tell me at which place in the code logcat complains about no database present
-Attach your entire code rather than pieces