I'm new to android development. I'm trying to use a pre-populated database whoch is stored in my assets folder. Log shows that the database gets opened but 'NO SUCH TABLE ERROR' is shown.I can't find any solution to this error. Please help.
MyDatabase.java :
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
/**
* Created by Deep on 22-06-2015.
*/
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "appver-1.db";
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// you can use an alternate constructor to specify a database location
// (such as a folder on the sd card)
// you must ensure that this folder is available and you have permission
// to write to it
//super(context, DATABASE_NAME, context.getExternalFilesDir(null).getAbsolutePath(), null, DATABASE_VERSION);
}
public SQLiteDatabase getData() {
SQLiteDatabase db = getReadableDatabase();
return db;
PlayActivity.java
public class PlayActivity extends Activity {
private MyDatabase db;
private SQLiteDatabase dbh;
private Cursor togo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = new MyDatabase(this);
dbh = db.getData();
setContentView(R.layout.activity_play);
}
public void onClickGo(View view){
String nm1;
String nm2;
String nm3;
String sendsql,send;
char last;
int l;
TextView tv2_text, tv4_text;
EditText et1_input;
tv2_text = (TextView)findViewById(R.id.tv2_text);
tv4_text = (TextView)findViewById(R.id.tv4_text);
et1_input = (EditText)findViewById(R.id.et1_input);
nm1 = et1_input.getText().toString();
l = nm1.length();
last = nm1.charAt(l - 1);
nm2 = "Africa";
nm3 = "A";
sendsql = "Select PLACES from countries where PLACES like " + "'" + nm3 + "%'" + " LIMIT 1" ;
togo = dbh.rawQuery(sendsql,null);
togo.moveToFirst();
send = togo.getString(0);
tv2_text.setText(send);
tv4_text.setText("A");
}
Aucun commentaire:
Enregistrer un commentaire