Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:17:13+00:00 2026-06-04T14:17:13+00:00

I am trying to get my application to display information that is in a

  • 0

I am trying to get my application to display information that is in a table I have set up in my database. From what I gather, the database is setup correctly and the code it’s correct but I don’t know what is causing the error. I will post all the code so to see if anyone here can help me figure is out.

Progress.class:

public class WorkoutProgress extends ListActivity {
   private DataBaseHelper datasource;
   TextView goal;
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.progress);
      goal = (TextView)findViewById(R.id.goal);
      datasource = new DataBaseHelper(this);
      datasource.open();
      fillData();
      datasource.close();
  }
  private void fillData() {
    Cursor c = datasource.getAllActs();
    startManagingCursor(c);
    String[] from = new String[] {DataBaseHelper.KEY_DATE,  
    DataBaseHelper.KEY_STEPS,DataBaseHelper.KEY_CALs };
    int[] to = { R.id.code, R.id.Days, R.id.BMI };
    SimpleCursorAdapter notes = new SimpleCursorAdapter (this, R.layout.notes_row, c,  from, to);
    setListAdapter(notes);               
  }
}

Database Helper:

public class DataBaseHelper
{
    public static final String KEY_ROWID = "_id";
    public static final String KEY_GOAL = "goal";
    public static final String KEY_Current = "cweight";
    public static final String KEY_Target = "nweight"; 

    public static final String KEY_ROWID2 = "_id";

    public static final String KEY_DATE = "date";
    public static final String KEY_STEPS = "steps";
    public static final String KEY_CALs = "calories";
    public static final String KEY_CALID = "_id";
    public static final String KEY_TOTALCALS = "totalcals";    
    private static final String TAG = "DBAdapter";
    private static final String DATABASE_NAME = "workout";
    private static final String DATABASE_TABLE = "goals";
    private static final String DATATABLE = "acts";
    private static final String CALTABLE = "cals";
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_CREATE =
     "create table goals (_id integer primary key autoincrement, "
     + "goal text not null, cweight number not null, " 
     + "nweight number not null);";
    private static final String DATABASE_CREATE2 =
        "create table acts (_id integer primary key autoincrement, "
                + "date text not null, steps text not null, " 
                + "calories number not null);"
    private final Context context; 
    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;
    public DataBaseHelper(Context ctx) 
    {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
           super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            db.execSQL(DATABASE_CREATE);
            db.execSQL(DATABASE_CREATE2);
        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, 
        int newVersion) 
        {
            Log.w(TAG, "Upgrading database from version " + oldVersion 
                + " to "
                + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS titles");
            onCreate(db);
        }
    }    
    public DataBaseHelper open() throws SQLException 
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }
    public void close() 
    {
        DBHelper.close();
    }
    public long insertTitle(String goal, int current, int target) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_GOAL, goal);
        initialValues.put(KEY_Current, current);
        initialValues.put(KEY_Target, target);
        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    public long insertActivity(String date, String steps, double Calories) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_DATE, date);
        initialValues.put(KEY_STEPS, steps);
        initialValues.put(KEY_CALs, Calories);
        return db.insert(DATATABLE, null, initialValues);
    }
    public boolean deleteTitle(long rowId) 
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + 
            "=" + rowId, null) > 0;
    }
    public void deleteFirst()
    {
        Cursor cursor = db.query(DATABASE_TABLE, null, null, null, null, null, null); 
        if(cursor.moveToFirst()) {
        long rowId = cursor.getLong(cursor.getColumnIndex(KEY_ROWID)); 
        db.delete(DATABASE_TABLE, KEY_ROWID +  "=" + rowId, null);
   }
}

public boolean deleteAct(long rowId) 
{
    return db.delete(DATATABLE, KEY_ROWID + 
            "=" + rowId, null) > 0;
}
//---retrieves all the titles---
public Cursor getAllGoals() 
{
    return db.query(DATABASE_TABLE, new String[] {
            KEY_ROWID, 
            KEY_GOAL,
            KEY_Current,
            KEY_Target}, 
            null, 
            null, 
            null, 
            null, 
            null);
}
public Cursor getAllActs() 
{
    return db.query(DATATABLE, new String[] {

            KEY_ROWID2, 

            KEY_DATE,
            KEY_STEPS,
            KEY_CALs}, 
            null, 
            null, 
            null, 
            null, 
            null);
}

//---retrieves a particular title---
public Cursor getGoal
(long rowId) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DATABASE_TABLE, new String[] {
                    KEY_ROWID,
                    KEY_GOAL, 
                    KEY_Current,
                    KEY_Target
                    }, 
                    KEY_ROWID + "=" + rowId, 
                    null,
                    null, 
                    null, 
                    null, 
                    null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}
public Cursor getAct(long rowId) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DATATABLE, new String[] {
                    KEY_ROWID2,
                    KEY_DATE, 
                    KEY_STEPS,
                    KEY_CALs
                    }, 
                    KEY_ROWID2 + "=" + rowId, 
                    null,
                    null, 
                    null, 
                    null, 
                    null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}
public boolean updateAct(long rowId, String date, 
        String steps, String cals) 
        {
            ContentValues args = new ContentValues();
            args.put(KEY_DATE, date);
            args.put(KEY_STEPS, steps);
            args.put(KEY_CALs, cals);
            return db.update(DATATABLE, args, 
                             KEY_ROWID2 + "=" + rowId, null) > 0;
        }
/*public boolean updateCals(long rowId, double cals) 
        {
            ContentValues args = new ContentValues();
            args.put(KEY_TOTALCALS, cals);
            return db.update(CALTABLE, args, 
                             KEY_CALID + "=" + rowId, null) > 0;
        }*/

//---updates a title---
public boolean updateTitle(long rowId, String isbn, 
String title, String publisher) 
{
    ContentValues args = new ContentValues();
    args.put(KEY_GOAL, isbn);
    args.put(KEY_Current, title);
    args.put(KEY_Target, publisher);
    return db.update(DATABASE_TABLE, args, 
                     KEY_ROWID + "=" + rowId, null) > 0;
} 
}

Logcat:

05-26 14:42:03.895: E/AndroidRuntime(345): FATAL EXCEPTION: main
05-26 14:42:03.895: E/AndroidRuntime(345): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.b00348312.workout/com.b00348312.workout.WorkoutProgress}: android.database.sqlite.SQLiteException: no such column: _id: , while compiling: SELECT _id, date, steps, calories FROM acts
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.os.Looper.loop(Looper.java:123)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-26 14:42:03.895: E/AndroidRuntime(345):  at java.lang.reflect.Method.invokeNative(Native Method)
05-26 14:42:03.895: E/AndroidRuntime(345):  at java.lang.reflect.Method.invoke(Method.java:521)
05-26 14:42:03.895: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-26 14:42:03.895: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-26 14:42:03.895: E/AndroidRuntime(345):  at dalvik.system.NativeStart.main(Native Method)
05-26 14:42:03.895: E/AndroidRuntime(345): Caused by: android.database.sqlite.SQLiteException: no such column: _id: , while compiling: SELECT _id, date, steps, calories FROM acts
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
05-26 14:42:03.895: E/AndroidRuntime(345):  at com.b00348312.workout.DataBaseHelper.getAllActs(DataBaseHelper.java:168)
05-26 14:42:03.895: E/AndroidRuntime(345):  at com.b00348312.workout.WorkoutProgress.fillData(WorkoutProgress.java:30)
05-26 14:42:03.895: E/AndroidRuntime(345):  at com.b00348312.workout.WorkoutProgress.onCreate(WorkoutProgress.java:25)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-26 14:42:03.895: E/AndroidRuntime(345):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-26 14:42:03.895: E/AndroidRuntime(345):  ... 11 more

Looking at the logcat it seems to be telling me that I am missing a column "_id" but I have modified the database to include this column which you can see in the database helper code above. Is there something I have missed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:17:15+00:00Added an answer on June 4, 2026 at 2:17 pm

    You may have modified the database to include the required column but this changes will not be actually implemented in the database until the method onCreate is called again or you implement the changes in the onUpgrade method and modify the version of the database.

    Try to uninstall and then install the app again on the emulator/phone so the onCreate method of your SQLiteOpenHelper implementation is called again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get my Blackberry application to display a custom modal dialog,
I'm trying to get a CakePHP application to work. For this, I've set up
I'm trying to get the current application name (the application that contains the current
I have developed a blog application of sorts that I am trying to allow
I am trying to get my web application deployed on Websphere 6.1 to display
I'm trying to achieve an application that allows to shoot a photo and display
I have a Silverlight application that needs to scroll some data (like stock information)
I'm trying to get a simple multi-threaded OpenGL application working. I have an update
I'm trying to create an application that will display all restaurants within the users
I'm developing an application which will display information derived from the EDID blocks (monitor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.