1

I am trying to create a database in Android. Here is the code that causes the error:

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

Here is my DatabaseHelper class:

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);
  }

} 

For some reason, calling helper.getWritableDatabase() causes a new window to pop up that says:

ActivityThread.handleCreateService(ActivityThread$CreateServiceData) Source not found.

What is the cause of this?

By the way, this is all in a Service and not in an Activity.

5
  • 2
    Please post all of your LogCat errors.
    – Sam
    Dec 13, 2012 at 23:01
  • My only LogCat error is: Fatal signal 6 (SIGABRT) at 0x0000001a7 (code=0) Dec 13, 2012 at 23:02
  • I don't think you should have more than one column declared as a primary key. Can't believe that would cause a popup though. Dec 13, 2012 at 23:07
  • Oh, and post more of your logcat. Need some context Dec 13, 2012 at 23:07
  • That actually solved my problem! Thanks! (I am new to SQL let alone Android) Dec 13, 2012 at 23:14

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.