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 8503057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:39:15+00:00 2026-06-11T01:39:15+00:00

My app is not displaying my data from my database. I cannot figure out

  • 0

My app is not displaying my data from my database. I cannot figure out why this is not working because i believe all my setup is properly done. Can anyone help me figure out why my data is not being displayed?

Here is my list view code :

 package com.work.plan;

 // multiple imports .... not included for length purpose

 public class WorkoutList extends Activity {

//====================================================================
//  Member variables

private Button addNewWorkout;
private WorkoutDbAdapter mDbHelper;
public static final int CREATE_WORKOUT = 1;
public static final int SET_WORKOUT = 2;
private String dateCreated = null;
private Calendar now = null; 
private SimpleDateFormat format = null;
private ListView myWorkoutList;



Intent prevIntent ;
String woName,userName;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.workout_list);

    addNewWorkout = (Button) findViewById(R.id.btnNewWorkout);
    prevIntent = getIntent();
    userName = prevIntent.getStringExtra("userName");

    // do the work for getting the current time and formatting it
    now = Calendar.getInstance();
    format = new SimpleDateFormat("EEE MMM dd hh:mm aaa");
    dateCreated = format.format(now.getTime());

     mDbHelper = new WorkoutDbAdapter(this);
     mDbHelper.open();

     myWorkoutList = (ListView)findViewById(R.id.workoutList);
     registerForContextMenu(myWorkoutList);

     myWorkoutList.setDivider(getResources().getDrawable(R.color.mainDivider));
     myWorkoutList.setDividerHeight(1);
     myWorkoutList.setOnItemClickListener(WorkoutListener);

     addNewWorkout.setOnClickListener(NewWorkout);

    fillData();
}

OnClickListener NewWorkout = new OnClickListener(){
     // ......... click listener code for my add button
     // ......... creates a new workout

};
//===============================================================================
//
@Override
public void onPause(){
    super.onPause();

}
//===============================================================================
//
@Override
public void onResume(){
    super.onResume();
    mDbHelper.open();
}

@Override
public void onDestroy(){
    super.onDestroy();
    mDbHelper.close();
}


//================================================================================
//
// Fill the data for UI rebuilds
private void fillData(){

    Log.d("User_NAME",""+ userName);

    Cursor workoutCursor = mDbHelper.fetchAllWorkouts();
    startManagingCursor(workoutCursor);

    String [] from = new String [] { WorkoutDbAdapter.KEY_WORKOUT_NAME,
                                    WorkoutDbAdapter.KEY_WORKOUT_CREATED_DATE ,WorkoutDbAdapter.KEY_WORKOUT_TYPE};

    int [] to = new int [] {R.id.dateCreatedLabel, R.id.nameLabel, R.id.typeLabel};

    SimpleCursorAdapter workouts = new SimpleCursorAdapter(this, R.layout.workout_row, workoutCursor, from, to);

    myWorkoutList.setAdapter(workouts);


}

@Override
public void onCreateContextMenu(ContextMenu menu , View v, ContextMenuInfo menuInfo){
    //........ stuff for my menu
}

@Override
public boolean onContextItemSelected(MenuItem item){
    //.......... code for my menu, handles menu clicks
    return super.onContextItemSelected(item);

}

//================================================================================

OnItemClickListener WorkoutListener = new OnItemClickListener(){

    public void onItemClick(AdapterView<?> arg0, View view, int position,
            final long id) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(WorkoutList.this)
        .setIcon(R.drawable.edit)
        .setTitle("Update Selected Workout")
        .setMessage("Would you like to update the current Workout? Click continue to proceed.")
        .setPositiveButton("Continue", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {
                final Intent i = new Intent(getBaseContext(), ExerciseList.class);
                i.putExtra(WorkoutDbAdapter.KEY_ROW_ID, id);
                i.putExtra("workoutName", woName);
                startActivityForResult(i, SET_WORKOUT);

            }
        })
        .setNegativeButton("Back", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();

            }
        });
        dialog.show();

    }

};
}

I then have a database adapter that creates the table ‘workouts’ in SQLite.

Here is the WorkoutDbAdapter code :

public class WorkoutDbAdapter {
//=========================================================================
    // Member Variables

     public static final String DATABASE_TABLE = "workouts";            
     public static final String KEY_ROW_ID = "_id";                 
     public static final String KEY_WORKOUT_EMAIL = "email";
     public static final String KEY_WORKOUT_NAME = "workout_name";              
     public static final String KEY_WORKOUT_CREATED_DATE = "created_date";
     public static final String KEY_WORKOUT_TYPE = "type";


     // string query that creates the table in the database
     static final String CREATE_TABLE_WORKOUTS  = ("CREATE TABLE " + DATABASE_TABLE + "("+ KEY_ROW_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                                                                   + KEY_WORKOUT_EMAIL + " TEXT NOT NULL,"
                                                                   + KEY_WORKOUT_NAME + " TEXT NOT NULL,"
                                                                   + KEY_WORKOUT_CREATED_DATE + " TEXT NOT NULL,"
                                                                   + KEY_WORKOUT_TYPE + " TEXT NOT NULL);");


     private final Context m_ClassContext;                          // reference to the current class
     private DatabaseHelper mDbHelper;                              // reference the database helper class
     private SQLiteDatabase mDb;                                    // reference to the SQLiteDatabase class


     // class constructor
     public WorkoutDbAdapter(Context ctx){
         this.m_ClassContext = ctx;
     }

     // open the database with a reference to this class
     public WorkoutDbAdapter open() throws SQLException{
         this.mDbHelper = new DatabaseHelper(m_ClassContext);
         this.mDb = mDbHelper.getWritableDatabase();
         return this;
     }

     // create a work out
     public long createWorkout(String email, String workoutName, String workoutDate, String workoutType){
         ContentValues values = new ContentValues();
         values.put(KEY_WORKOUT_EMAIL, email);
         values.put(KEY_WORKOUT_NAME, workoutName);
         values.put(KEY_WORKOUT_CREATED_DATE, workoutDate);
         values.put(KEY_WORKOUT_TYPE, workoutType);
         long insertValue = this.mDb.insert(DATABASE_TABLE, null, values);
         return insertValue;

     }

     // delete a Work out
     public boolean deleteWorkout(long rowId){
         return this.mDb.delete(DATABASE_TABLE, KEY_ROW_ID + "=" +rowId,null) > 0;
     }

//**My error was here**
     // fetch allWorkouts for this user
     public Cursor fetchAllWorkouts(String email){
         return this.mDb.query(DATABASE_TABLE, new String[]{KEY_ROW_ID,
KEY_WORKOUT_EMAIL, KEY_WORKOUT_NAME, KEY_WORKOUT_CREATED_DATE, KEY_WORKOUT_TYPE},
KEY_WORKOUT_EMAIL+ "='" +email+"'",null,null,null,null); // i removed a null and it works
     }

     // fetch a work out
     public Cursor fetchWorkout(long rowId) throws SQLException{
         Cursor mCursor = mDb.query(true, DATABASE_TABLE,new String[]{KEY_ROW_ID,
                    KEY_WORKOUT_EMAIL,KEY_WORKOUT_NAME,KEY_WORKOUT_CREATED_DATE, KEY_WORKOUT_TYPE}, KEY_ROW_ID + "="+rowId, null,null,null,null,null);
         if(mCursor != null){
             mCursor.moveToFirst();
         }
         return mCursor;
     }


     public boolean updateWorkout(long rowId, String email, String workoutName, String createdDate, String workoutType){
         ContentValues values = new ContentValues();
         values.put(KEY_WORKOUT_EMAIL, email);
         values.put(KEY_WORKOUT_NAME, workoutName);
         values.put(KEY_WORKOUT_CREATED_DATE, createdDate);
         values.put(KEY_WORKOUT_TYPE, workoutType);


         return this.mDb.update(DATABASE_TABLE, values, KEY_ROW_ID +"="+rowId, null)> 0;
     }

     // close the database
     public void close(){
         if(mDbHelper != null){
             mDbHelper.close();
             mDb.close();
         }

     }
}
  • 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-11T01:39:16+00:00Added an answer on June 11, 2026 at 1:39 am

    You are probably running into problems with your database code and the cursor size is 0. Watch logcat for failed sql queries and debug the size of the cursor.

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

Sidebar

Related Questions

I am working on a Website which is displaying all the apps from the
WEB APP not native, no Objective-C This is so simple it hurts. <input type=date
This is a WEB APP not a native app. Please no Objective-C NS commands.
I am working on an old ASP web app (not .net) and I need
I was uploading the data to App Engine (not dev server) through loader class
The following batch request for retrieve friends using the same app is not working:
My app is receiving data from a BlueTooth device 4 times a second, parsing
I'm displaying a scoreboard from a SQLite table in my app. I want to
Hello I am taking records from core data entity and displaying it in tableview.
Hi onListItemClick for listview is not working. Here i am fetching datas from SQLite

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.