我的 logcat 中有错误。这里
Caused by: android.database.sqlite.SQLiteException: table japanesebaybayin already exists (code 1): , while compiling: CREATE TABLE japanesebaybayin (_id INTEGER, language_japaneseTEXT, language_japaneseeaTEXT, language_tagalogTEXT, language_definitionTEXT);
有人可以帮我找到正确的解决方案吗?我无法检索数据库中的特定行。
这是我的代码:
public class TranslationActivity extends Activity implements OnClickListener{
protected SQLiteDatabase db;
protected EditText txtenglishAplha;
protected TextView tvdefinition;
protected TextView tvtagalog;
public static final String KEY_ROWID="_id";
public static final String KEY_JAPANESE="language_japanese";
public static final String KEY_JAPANESEEA="language_japaneseea";
public static final String KEY_TAGALOG="language_tagalog";
public static final String KEY_DEFINITION="language_definition";
private final String DATABASE_NAME = "mydb";
private final String DATABASE_TABLE = "japanesebaybayin";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.translation_main);
db = this.openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);
//db.execSQL("CREATE TABLE IF NOT EXISTS " +
// DATABASE_TABLE +
// " (rowid INTEGER, japancharacter VARCHAR," +
// " japanalphabet VARCHAR, tagalog VARCHAR, " +
// " definition VARCHAR);");
db.execSQL( "CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER, "+
KEY_JAPANESE + "TEXT, " +
KEY_JAPANESEEA + "TEXT, " +
KEY_TAGALOG + "TEXT, " +
KEY_DEFINITION + "TEXT);"
);
db.execSQL("INSERT INTO " +
DATABASE_TABLE +
" Values (1,'\u3042\u308A\u304C\u3068\u3046','arigato','salamat','giving thanks');");
db.execSQL("INSERT INTO " +
DATABASE_TABLE +
" Values (2,'\u3042\u308A\u304C\u3068\u3046','sayonara','paalam','giving goodbye');");
//Buttons
Button btnsearch = (Button) findViewById(R.id.btnsearch);
btnsearch.setOnClickListener(this);
//Edit Texts
txtenglishAplha = (EditText) findViewById(R.id.txtenglishAlpha);
txtenglishAplha.requestFocus();
//Text Views
tvdefinition = (TextView) findViewById(R.id.tvdefinition);
tvtagalog = (TextView) findViewById(R.id.tvtagalog);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.translation, menu);
return true;
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
String tagalog="", definition="", japanalpha;
Cursor cursor;
switch (view.getId()){
case R.id.btnsearch:
japanalpha = txtenglishAplha.getText().toString();
String[] columns = new String[] {KEY_JAPANESEEA, KEY_TAGALOG, KEY_DEFINITION};
cursor = db.query(DATABASE_TABLE, columns, KEY_JAPANESEEA + "='"+japanalpha+"'", null, null, null, null);
//String qjoiner = "SELECT japanalphabet, tagalog, definition from " +DATABASE_TABLE+ " where japanalphabet ='"+japanalpha+"';";
//Log.i("-----search table joiner----- ",qjoiner);
// cursor=db.rawQuery(qjoiner, null);
if(cursor != null){
cursor.moveToFirst();
tagalog = cursor.getString(cursor.getColumnIndex(KEY_TAGALOG)).toString();
definition = cursor.getString(cursor.getColumnIndex(KEY_DEFINITION)).toString();
tvtagalog.setText(tagalog);
tvdefinition.setText(definition);
}else{
tvtagalog.setText(tagalog);
tvdefinition.setText(definition);
}
break;
}
}
}