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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:19:13+00:00 2026-06-18T09:19:13+00:00

I have a database (sqlite on Android) with several columns: _id, datum, hour, note

  • 0

I have a database (sqlite on Android) with several columns:
_id, datum, hour, note

The database is created by this:

    private static final String DATABASE_CREATE =
    "create table worked (_id integer primary key autoincrement, "
    + "datum text not null, hour text not null, " 
    + "note text);";

At the end I want the total of hours and minutes out of my database and return it to my mainActivity.

I tried to do this:

public int getTotalHours(){
    Cursor c = db.rawQuery("select hour from " + DATABASE_TABLE, null);
    int total = 0;
    Date hours = new Date();
    SimpleDateFormat hourFormat = new SimpleDateFormat("HH:mm");
    c.moveToFirst();
    for(int i = 0; i<c.getCount(); i++){
        String uur = c.getString(i);
        try {
            hours = hourFormat.parse(uur);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        total += hours.getHours();
    }
    return total;
}

But I’m already getting a error in my query. I also dont know how if the data is being extracted at the right way, I cant test that because of the query error…

The error I’m getting:

Failed to read row 0, column 1 from a cursorWindow which has 5 rows, 1 columns.

I hope I was in the right way, and that somebody can help me.
Thanks in advance!

  • 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-18T09:19:14+00:00Added an answer on June 18, 2026 at 9:19 am

    Properly loop through your records, retrieve the proper column index, and close your cursor:

    public int getTotalHours(){
        Cursor c = db.rawQuery("select hour from " + DATABASE_TABLE, null);
        if (c == null)
            return 0;
    
        try{
            int total = 0;
            Date hours = new Date();
            SimpleDateFormat hourFormat = new SimpleDateFormat("HH:mm");
            while(c.moveToNext())
            {
                String uur = c.getString(0);
                try {
                    hours = hourFormat.parse(uur);
                    total += hours.getHours();
                } catch (ParseException e) {
                    e.printStackTrace();
                }           
            }
    
            return hours;
        }finally{
            c.close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE
I have a database created like: mDatabase.execSQL(FTS_TABLE_CREATE); where FTS_TABLE_CREATE : private static final String
I have this error: 12-07 15:27:11.567: E/AndroidRuntime(15797): Caused by: android.database.sqlite.SQLiteException: no such column: recipient:
I have the data in the android(Sqlite Database).How to transfer this database data's to
i have created one android application that was connecting to sqlite database. and i
I have this database structure: protected static final String Buildings = CREATE TABLE +
I was newbie in using sqlite database android. and now I have a problem
I have a SQLite database setup for my android application and I have it
I have a table in SQLite database of Android which has a column RANK
I have a SQLite database, and several tables within that datbase. I am developing

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.