1

我正在尝试在 Android 中创建一个数据库。这是导致错误的代码:

DatabaseHelper helper = new DatabaseHelper(getApplicationContext());
SQLiteDatabase db = helper.getWritableDatabase();

这是我的 DatabaseHelper 类:

package com.example.livelab;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

  public static final String TABLE_CALLS = "calls";
  public static final String COLUMN_ID = "_id";
  public static final String COLUMN_CALL_NUMBER = "number";
  public static final String COLUMN_CALL_DATE = "date";
  public static final String COLUMN_CALL_DURATION = "duration";

  private static final String DATABASE_NAME = "LiveLab.db";
  private static final int DATABASE_VERSION = 1;

  // SQL statement for creating our CALLS table.
  private static final String CALLS_CREATE = "create table "
      + TABLE_CALLS + "(" + COLUMN_ID
      + " integer primary key autoincrement, " + COLUMN_CALL_NUMBER
      + " integer primary key autoincrement, " + COLUMN_CALL_DATE
      + " integer primary key autoincrement, " + COLUMN_CALL_DURATION
      + " text not null);";

   public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
   }

   @Override
   public void onCreate(SQLiteDatabase database) {
    database.execSQL(CALLS_CREATE);
   }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(DatabaseHelper.class.getName(),
        "Upgrading database from version " + oldVersion + " to "
             + newVersion + ", which will destroy all old data");
     db.execSQL("DROP TABLE IF EXISTS " + TABLE_CALLS);
    onCreate(db);
  }

} 

出于某种原因,调用 helper.getWritableDatabase() 会弹出一个新窗口,上面写着:

ActivityThread.handleCreateService(ActivityThread$CreateServiceData) 找不到源。

这是什么原因?

顺便说一句,这一切都在服务中,而不是在活动中。

4

0 回答 0