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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:56:37+00:00 2026-05-15T13:56:37+00:00

I have a problem programming with Android SDK 1.6. I’m doing the same things

  • 0

I have a problem programming with Android SDK 1.6. I’m doing the same things of the “notepad example” but the program crash when I try some query. If I try to do a query directly in to the DatabaseHelper create() method it goes, but out of this function it doesn’t. Do you have any idea?

This is the source:

public class DbAdapter {

    public static final String KEY_NAME = "name";
    public static final String KEY_TOT_DAYS = "totdays";
    public static final String KEY_ROWID = "_id";

    private static final String TAG = "DbAdapter";
    private DatabaseHelper mDbHelper;
    private SQLiteDatabase mDb;

    private static final String DATABASE_NAME = "flowratedb";
    private static final String DATABASE_TABLE = "girl_data";
    private static final String DATABASE_TABLE_2 = "girl_cyle";
    private static final int DATABASE_VERSION = 2;
    /**
     * Database creation sql statement
     */
    private static final String DATABASE_CREATE =
            "create table "+DATABASE_TABLE+" (id integer, name text not null, totdays int);";
    private static final String DATABASE_CREATE_2 =
        "create table "+DATABASE_TABLE_2+" (ref_id integer, day long not null);";

    private final Context mCtx;

    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_CREATE_2);
            db.delete(DATABASE_TABLE, null, null);
            db.delete(DATABASE_TABLE_2, null, null);
        }

        @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 "+DATABASE_TABLE);
            db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE_2);
            onCreate(db);
        }
    }
    public DbAdapter(Context ctx) {
        this.mCtx = ctx;
    }
    public DbAdapter open() throws SQLException {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }
    public void close() {
        mDbHelper.close();
    }
    public long createGirl(int id,String name, int totdays) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_ROWID, id);
        initialValues.put(KEY_NAME, name);
        initialValues.put(KEY_TOT_DAYS, totdays);
        return mDb.insert(DATABASE_TABLE, null, initialValues);
    }
    public long createGirl_fd_day(int refid, long fd) {
        ContentValues initialValues = new ContentValues();
        initialValues.put("ref_id", refid);
        initialValues.put("calendar", fd);
        return mDb.insert(DATABASE_TABLE, null, initialValues);
    }
    public boolean updateGirl(int rowId, String name, int totdays) {
        ContentValues args = new ContentValues();
        args.put(KEY_NAME, name);
        args.put(KEY_TOT_DAYS, totdays);

        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }
    public boolean deleteGirlsData() {
        if (mDb.delete(DATABASE_TABLE_2, null, null)>0)
            if(mDb.delete(DATABASE_TABLE, null, null)>0)
                return true;
        return false;
    }
    public Bundle fetchAllGirls() {
        Bundle extras = new Bundle();
        Cursor cur = mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME,
                KEY_TOT_DAYS}, null, null, null, null, null);
        cur.moveToFirst();
        int tot = cur.getCount();
        extras.putInt("tot", tot);
        int index;
        for (int i=0;i<tot;i++){
            index=cur.getInt(cur.getColumnIndex("_id"));
            extras.putString("name"+index, cur.getString(cur.getColumnIndex("name")));
            extras.putInt("totdays"+index, cur.getInt(cur.getColumnIndex("totdays")));
        }
        cur.close();
        return extras;
    }
    public Cursor fetchGirl(int rowId) throws SQLException {

        Cursor mCursor =
                mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                        KEY_NAME, KEY_TOT_DAYS}, KEY_ROWID + "=" + rowId, null,
                        null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }
    public Cursor fetchGirlCD(int rowId) throws SQLException {

        Cursor mCursor =
                mDb.query(true, DATABASE_TABLE_2, new String[] {"ref_id",
                        "day"}, "ref_id=" + rowId, null,
                        null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }
}
  • 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-15T13:56:38+00:00Added an answer on May 15, 2026 at 1:56 pm

    i had the same problem, i solved it looking at your comment about creating a new database.

    The onCreate() method is called only when creating the database. If database is allready created (it creates the first time you try the code :), onCreate will not be called the next time you run the emulator.
    so modifying the sql statement in onCreate() method wont change the table the next time you start the emulator, and you will still have the table that was created the first time you started your emulator and created the database. with this scenario you will have faulty sql statements in you code.
    second scenario is that you used the adb-sqlite3 console (shell) program and modified the table(s). Database is already created, so onCreate() wont be called – and no matter what code you have to describe the table in you onCreate() the table will be the same as you modified it through shell…

    my problem was that i deleted the tables using shell, and expected onCreate to re-create them, but the database was already created, and had no tables anymore.

    So, the conclusion is that the first time you create the DATABASE all the tables are created, and if you need to modify them, modify them through shell or delete the database so the onCreate will be called nes time you run your program.

    gosh, this text sounds like a infinite loop 🙂
    sorry for complicating the answer, im realy realy tiered already… 🙁

    good luck!

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

Sidebar

Ask A Question

Stats

  • Questions 488k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For &src[i] am I getting the address of the character… May 16, 2026 at 8:32 am
  • Editorial Team
    Editorial Team added an answer GWT and GAE are two separate products, yes they can… May 16, 2026 at 8:32 am
  • Editorial Team
    Editorial Team added an answer Support for this was introduced in PHP 5.3. For versions… May 16, 2026 at 8:32 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

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.