I'm attempting to execute an SQL Query via android - and I am currently unable to do so. I'm getting a fatal error and the application closes when attempting to perform a simple query which I have verified to be valid: SELECT * FROM TblMovie WHERE MovieYear = 1975
However - when I attempt to do so within my app:
MainActivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbhelper = new DBHelper(this);
List<String> list = dbhelper.getData();
TextView textView1 = (TextView) findViewById(R.id.textView1);
TextView textView2 = (TextView) findViewById(R.id.textView2);
textView1.setText(list.get(0));
textView2.setText(list.get(1));
...
DBHelper:
public List<String> getData() {
db = this.getReadableDatabase();
List<String> data = new ArrayList<String>();
Cursor c = db.rawQuery("SELECT * FROM TblMovie WHERE MovieYear = 1975", null);
while (c.moveToNext()) {
data.add(c.getString(0));
data.add(c.getString(1));
}
c.close();
db.close();
return data;
}
Logcat:
05-19 10:24:59.983: E/AndroidRuntime(24736): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: android.database.sqlite.SQLiteException: no such table: TblMovie (code 1): , while compiling: SELECT * FROM TblMovie WHERE MovieYear = 1975
http://pastebin.com/0mAD87jJ
Also - I have found this article as reference:
No such table: (code 1) while compiling: SELECT * FROM event
I have tried running it on my tablet instead of the emulator - still does not work. I also tried clearing data - that does not work either. I have the database in my assets folder so I'm unsure as to why it isn't working.
EDIT:
Why the downvote? I'm pretty sure this is a valid and not terribly written / documented / researched issue.