mardi 19 mai 2015

SQLiteException: no such table: (code 1)

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{http://ift.tt/1bV4dal}: android.database.sqlite.SQLiteException: no such table: TblMovie (code 1): , while compiling: SELECT * FROM TblMovie WHERE MovieYear = 1975



http://ift.tt/1cMVm2I

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.

Any input is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire