开发者

Error with android DBAdapter class

here is the error from the logcat of my program.

06-24 01:35:04.213: INFO/ActivityManager(587): Starting activity: Intent { comp={one.two/one.two.Arrival} } 06-24 01:35:04.521: ERROR/DBDroid(1048): android.database.sqlite.SQLiteException: no such table: port: , while compiling: SELECT KEY_STATUS, KEY_ID, KEY_ARRIVAL, KEY_DESTINATION, KEY_FERRY FROM ferry 06-24 01:35:05.026: INFO/ActivityManager(587): Displayed activity one.two/.Arrival: 805 ms

It seems that it is stated that there is no table called port. But i do have a table called port placed into the emulator , under data/data/one.two/databases

And here is my partial code of DBAdapter:

    public class DBAdapter extends ListActivity {
public static  String KEY_STATUS = "status";
public static  String KEY_ID = "id";
public static  String KEY_ARRIVAL = "arrival";
public static  String KEY_DESTINATION = "destination";
public static  String KEY_FERRY = "ferry";

private static final String DATABASE_NAME = "ferry";
private static final String DATABASE_TABLE = "port";

private static final int DATABASE_VERSION = 1;

 private static  Context context;
 private static DatabaseHelper DBHelper;
 private static SQLiteDatabase db;

By the way does anyone here knows what does this method do :

public DBAdapter(Context ctx)
{
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper
{
    DatabaseHelper(Context context)
    {
        s开发者_如何转开发uper(context, "ferry", null, 1);
    }

@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
    }
}//end DatabaseHelper

// ---opens the database---
public DBAdapter open() throws SQLException
{
    db = DBHelper.getWritableDatabase();
    return this;
}

// ---closes the database---
public void close()
{
    DBHelper.close();
}

Thank you.


You should put table creation code in DatabaseHelper.onCreate() method - SQL CREATE statements for all tables you're going to use in other queries.

edit:

Unless you're providing ".db" file already created outside Android (e.g. using SQLite Database Browser tool - http://sqlitebrowser.sourceforge.net) within your application package (e.g. already populated with data). Then you don't have to put any code here (moreover if you put code that will try to create table that exists you'll get an SQL exception).


Are you absolutely sure the table exists ?

Try to open database invoking following commands from shell (I guess DATABASE_NAME is the name of database file):

adb shell
sqlite3 /data/data/one.two/databases/ferry

SQLite console should open. And then list tables:

.tables

Use .quit to exit SQLite.

edit:

If your database file is ferry.db then DATABASE_NAME should also be "ferry.db"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜