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

  • Home
  • SEARCH
  • 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 6073719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:18:07+00:00 2026-05-23T10:18:07+00:00

Hey i recently started android development and encountered a problem when saving/loading data from

  • 0

Hey i recently started android development and encountered a problem when saving/loading data from a database. I took the database class from here with some slight changes.

My problem is i got an activity with some edittexts. At onCreate the strings from the database should be written into the edittexts and when pressing the button the data in the database should be updated and activity closed. For the case that the database is empty I added an if-clause with cursor.getCount!=0 for reading the database, but this condition never gets true.

Here is my code

package com.gabrielisonline.timetable;

public class DurationActivity extends Activity {

DbAdapter dba;

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

    Button saveButton = (Button) findViewById(R.id.duration_button1);
    saveButton.setOnClickListener(new SaveButtonListener());

    dba = new DbAdapter(this);
    dba.open(); 
    Cursor c = dba.fetchAllDurations();

    if (c.getCount() != 0)  {
        int i = c.getColumnIndex(DbAdapter.KEY_TIME);

        ((EditText) findViewById(R.id.duration_length)).setText(dba.fetchDuration(0).getString(i));
        ((EditText) findViewById(R.id.duration_lesson1)).setText(dba.fetchDuration(1).getString(i));
        ((EditText) findViewById(R.id.duration_lesson2)).setText(dba.fetchDuration(2).getString(i));
        ((EditText) findViewById(R.id.duration_lesson3)).setText(dba.fetchDuration(3).getString(i));
        ((EditText) findViewById(R.id.duration_lesson4)).setText(dba.fetchDuration(4).getString(i));
        ((EditText) findViewById(R.id.duration_lesson5)).setText(dba.fetchDuration(5).getString(i));
        ((EditText) findViewById(R.id.duration_lesson6)).setText(dba.fetchDuration(6).getString(i));
        ((EditText) findViewById(R.id.duration_lesson7)).setText(dba.fetchDuration(7).getString(i));
        ((EditText) findViewById(R.id.duration_lesson8)).setText(dba.fetchDuration(8).getString(i));
        ((EditText) findViewById(R.id.duration_lesson9)).setText(dba.fetchDuration(9).getString(i));
        ((EditText) findViewById(R.id.duration_lesson10)).setText(dba.fetchDuration(10).getString(i));
    }


}

public class SaveButtonListener implements OnClickListener {
    @Override
    public void onClick(View v) {

        String l = ((EditText) findViewById(R.id.duration_length)).getText().toString();
        String l1 = ((EditText) findViewById(R.id.duration_lesson1)).getText().toString();
        String l2 = ((EditText) findViewById(R.id.duration_lesson2)).getText().toString();
        String l3 = ((EditText) findViewById(R.id.duration_lesson3)).getText().toString();
        String l4 = ((EditText) findViewById(R.id.duration_lesson4)).getText().toString();
        String l5 = ((EditText) findViewById(R.id.duration_lesson5)).getText().toString();
        String l6 = ((EditText) findViewById(R.id.duration_lesson6)).getText().toString();
        String l7 = ((EditText) findViewById(R.id.duration_lesson7)).getText().toString();
        String l8 = ((EditText) findViewById(R.id.duration_lesson8)).getText().toString();
        String l9 = ((EditText) findViewById(R.id.duration_lesson9)).getText().toString();
        String l10 = ((EditText) findViewById(R.id.duration_lesson10)).getText().toString(); 

        dba.updateDuration(0,l);
        dba.updateDuration(1,l1);
        dba.updateDuration(2,l2);
        dba.updateDuration(3,l3);
        dba.updateDuration(4,l4);
        dba.updateDuration(5,l5);
        dba.updateDuration(6,l6);
        dba.updateDuration(7,l7);
        dba.updateDuration(8,l8);
        dba.updateDuration(9,l9);
        dba.updateDuration(10,l10);             

        dba.close();

        finish();
    }
}
}

Thanks for your help!

EDIT:

Thanks for your answers guys. The problem was indeed thet I didn’t really write something into the databse. Instead of just using updateDuration i changed the code in the onClick method to:

if (c.getCount() != 0)  {           
dba.updateDuration(1,l);
dba.updateDuration(2,l1);
dba.updateDuration(3,l2);
dba.updateDuration(4,l3);
dba.updateDuration(5,l4);
dba.updateDuration(6,l5);
dba.updateDuration(7,l6);
dba.updateDuration(8,l7);
dba.updateDuration(9,l8);
dba.updateDuration(10,l9);
dba.updateDuration(11,l10); 
} else {
dba.createDuration(l);
dba.createDuration(l1);
dba.createDuration(l2);
dba.createDuration(l3);
dba.createDuration(l4);
dba.createDuration(l5);
dba.createDuration(l6);
dba.createDuration(l7);
dba.createDuration(l8);
dba.createDuration(l9);
dba.createDuration(l10);
}

Now everything is working. I thought the update method would be enough also for the first write to the db (createDuration calls the create method on the database in DbAdapter and updateDuration calls update).

  • 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-05-23T10:18:08+00:00Added an answer on May 23, 2026 at 10:18 am

    Have you ever written anything to the DB? do you know that the DB definitely has data in it? If not try installing a SQLLite browser such as http://sqlitebrowser.sourceforge.net/ and have a look at the tables.

    That should help you identify if the problem is with writing to the table or reading from it. Might be able to help further if you provide your DBAdapter class

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

Sidebar

Related Questions

Hey. I only recently started using Python, and my friend suggested using Twisted as
Hey all, I have the following problem. I recently added an extra column to
Hey everyone! Started programming with Bluetooth on Android awhile ago. But now I've run
Hey, Using CorePlot recently but the Problem is, that the Labels I set don´t
Hey guys I have a query that selects data and organizes but not in
hey huys im counting my table with this code: $county = mysql_query(SELECT COUNT(id) from
Hey guys, so I recently purchased a cheap vps for me to play around
hey i am new to the macports thing as i recently switched to the
I recently took all my code a manually imported it into an eclipse project
i recently migrated my whole DB from myisam to innodb. I am fairly new

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.