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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:28:10+00:00 2026-06-04T20:28:10+00:00

I have 2 activities, the first one is the DataBase helper and the second

  • 0

I have 2 activities, the first one is the DataBase helper and the second one is the main activity.

Now, I am trying to set radio buttons based on the name that are on table DATABASE_TABLE_SETTINGS in the column KEY_b_NAME.

I tried to set the following code on the main activity and get a cursor that checks if !c.isAfterLast, and if this is true I want it to set new radio button with the id of KEY_ROW_b_ID and the name of KEY_b_NAME.

after lunching it, I get this error:

05-27 19:33:44.055: E/AndroidRuntime(2189): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tamar.efrat/com.tamar.efrat.Tamar_appActivity}: java.lang.NullPointerException

The for loop in the main activity is:

    DatBas dbc = new DatBas(Tamar_appActivity.this);
    dbc.open();
    SQLiteDatabase tdb = null;
    String[] columns = new String[] { DatBas.KEY_ROW_B_ID, DatBas.KEY_B_NAME };
    Cursor c = tdb.query(DatBas.DATABASE_TABLE_SETTINGS, columns, null, null, null, null,
            null);

    int iRawBId = c.getColumnIndex(DatBas.KEY_ROW_B_ID);
    int iBName = c.getColumnIndex(DatBas.KEY_B_NAME);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        RadioGroup radiogroup = (RadioGroup)    
                    findViewById(R.id.bNameSelectGroup);
        RadioButton rdbtn = new RadioButton(this);
        rdbtn.setId(iRawBId);
        rdbtn.setText(iBName);
        radiogroup.addView(rdbtn);  
    }
    dbc.close();

The code of the DataBase helper is:

public class DatBas {

    public static final String KEY_ROWID = "_id";
    public static final String KEY_SHOURS = "start_hour";
    public static final String KEY_SMINUTE = "start_minute";
    public static final String KEY_SDATE = "start_date";
    public static final String KEY_AMOUNT = "amount";
    public static final String KEY_SIDE = "side";
    public static final String KEY_KIND = "kind";

    public static final String KEY_ROW_b_ID = "_id";
    public static final String KEY_b_IMAGE_PATH = "uri_b";
    public static final String KEY_b_NAME = "b_name";
    public static final String KEY_b_GENDER = "b_gender";
    public static final String KEY_b_BORN_DATE_YEAR = "b_age_year";
    public static final String KEY_b_BORN_DATE_MONTH = "b_age_month";
    public static final String KEY_b_BORN_DATE_DAY = "b_age_day";

    private static final String DATABASE_NAME = "TamatDB";
    private static final String DATABASE_TABLE = "stop_watch_records";
    private static final String DATABASE_TABLE_SETTINGS = "settings";

    private static final int DATABASE_VERSION = 3 ;

    private TamarDatabase thdb;
    private static Context tcontext;
    private SQLiteDatabase tdb;

    private static class TamarDatabase extends SQLiteOpenHelper {

        public TamarDatabase(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            String ctData = "CREATE TABLE  " + DATABASE_TABLE + " ( "
                    + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + KEY_SHOURS + " TEXT, " + KEY_SMINUTE
                    + " TEXT, " + KEY_SDATE + " TEXT, "
                    + KEY_AMOUNT + " TEXT, " + KEY_SIDE
                    + " TEXT, " + KEY_KIND + " TEXT );";
            db.execSQL(ctData);

            String ctSettings = "CREATE TABLE " + DATABASE_TABLE_SETTINGS
                    + " ( " + KEY_ROW_b_ID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + KEY_b_IMAGE_PATH + " TEXT, " + KEY_b_NAME
                    + " TEXT, " + KEY_b_GENDER + " TEXT, "
                    + KEY_b_BORN_DATE_YEAR + " TEXT, "
                    + KEY_b_BORN_DATE_MONTH + " TEXT, "
                    + KEY_b_BORN_DATE_DAY + " TEXT);";
            db.execSQL(ctSettings);

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_SETTINGS);
            onCreate(db);
        }
    }

    public DatBas(Context c) {
        tcontext = c;
    }

    public DatBas open() throws SQLiteException {
        thdb = new TamarDatabase(tcontext);
        tdb = thdb.getWritableDatabase();
        return this;
    }

    public SQLiteDatabase getReadableDatabase() throws SQLiteException {
        thdb = new TamarDatabase(tcontext);
        tdb = thdb.getReadableDatabase();
        return tdb;
    }


    public void close() {
        tdb.close();
    }

    public long createEntry(String sh, String sm, String sd, String at,
            String tside, String tkind) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_SHOURS, sh);
        cv.put(KEY_SMINUTE, sm);
        cv.put(KEY_SDATE, sd);
        cv.put(KEY_AMOUNT, at);
        cv.put(KEY_SIDE, tside);
        cv.put(KEY_SIDE, tkind);

        return tdb.insert(DATABASE_TABLE, null, cv);
    }

    public long createEntrySettings(String pt, String bn, String bg,
            String bbdy, String bbdm, String bbdd) {
        ContentValues cv2 = new ContentValues();
        cv2.put(KEY_b_IMAGE_PATH, pt);
        cv2.put(KEY_b_NAME, bn);
        cv2.put(KEY_b_GENDER, bg);
        cv2.put(KEY_b_BORN_DATE_YEAR, bbdy);
        cv2.put(KEY_b_BORN_DATE_MONTH, bbdm);
        cv2.put(KEY_b_BORN_DATE_DAY, bbdd);

        return tdb.insert(DATABASE_TABLE_SETTINGS, null, cv2);
    }

    public String getData() {
        String[] columns = new String[] { KEY_ROWID, KEY_SHOURS, KEY_SMINUTE,
                KEY_SDATE, KEY_AMOUNT, KEY_SIDE, KEY_KIND };
        Cursor c = tdb.query(DATABASE_TABLE, columns, null, null, null, null,
                null);
        String results = "";

        int iRaw = c.getColumnIndex(KEY_ROWID);
        int iShours = c.getColumnIndex(KEY_SHOURS);
        int iSminute = c.getColumnIndex(KEY_SMINUTE);
        int iDate = c.getColumnIndex(KEY_SDATE);
        int iAmount = c.getColumnIndex(KEY_AMOUNT);
        int iSide = c.getColumnIndex(KEY_SIDE);
        int iKind = c.getColumnIndex(KEY_KIND);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            results = results + "the id is " + c.getString(iRaw)
                    + " the sart hour is " + " " + c.getString(iShours)
                    + " the start minute is " + " " + c.getString(iSminute)
                    + " the start date is " + " " + c.getString(iDate)
                    + " the amount is " + " " + c.getString(iAmount)
                    + " the side is " + " " + c.getString(iSide)
                    + " the kind is " + " " + c.getString(iKind) + "\n";
        }
        return results;
    }

    public String getDataSettings() {
        String[] columns = new String[] { KEY_ROW_b_ID, KEY_b_IMAGE_PATH,
                KEY_b_NAME, KEY_b_GENDER, KEY_b_BORN_DATE_YEAR,
                KEY_b_BORN_DATE_MONTH, KEY_b_BORN_DATE_DAY };
        Cursor c = tdb.query(DATABASE_TABLE_SETTINGS, columns, null, null,
                null, null, null);
        String results = "";

        int iRawbId = c.getColumnIndex(KEY_ROW_b_ID);
        int iBIPath = c.getColumnIndex(KEY_b_IMAGE_PATH);
        int iBName = c.getColumnIndex(KEY_b_NAME);
        int iGender = c.getColumnIndex(KEY_b_GENDER);
        int iBBDateYear = c.getColumnIndex(KEY_b_BORN_DATE_YEAR);
        int iBBDateMonth = c.getColumnIndex(KEY_b_BORN_DATE_MONTH);
        int iBBDateDay = c.getColumnIndex(KEY_b_BORN_DATE_DAY);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            results = results + " id " + " " + c.getString(iRawbId)
                    + " path " + " " + c.getString(iBIPath)
                    + " name " + " " + c.getString(iBName)
                    + " gender " + " " + c.getString(iGender)
                    + " year " + " " + c.getString(iBBDateYear)
                    + " month " + " " + c.getString(iBBDateMonth)
                    + " day " + " " + c.getString(iBBDateDay) + "\n";
        }
        return results;
    }

    public String getDataSettingsbName() {
        String[] columns = new String[] { KEY_ROW_b_ID, KEY_b_NAME };
        Cursor c = tdb.query(DATABASE_TABLE_SETTINGS, columns, null, null,
                null, null, null);
        String results = "";

        int iRawbId = c.getColumnIndex(KEY_ROW_b_ID);
        int iBName = c.getColumnIndex(KEY_b_NAME);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            results = c.getString(iRawbId)+ c.getString(iBName)+ "\n";
        }
        return results;
    }

    public DatBas delete() {
        tdb.delete(DATABASE_TABLE, null, null);
        tdb.delete(DATABASE_TABLE_SETTINGS, null, null);
        return null;
    }

}
  • 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-04T20:28:12+00:00Added an answer on June 4, 2026 at 8:28 pm

    Your Sqlitedatabase instance is null so it throws a NullPointerException when you try to do a query on it:

    SQLiteDatabase tdb = null; // this is null so when you query the database it will throw an exception
    String[] columns = new String[] { DatBas.KEY_ROW_B_ID, DatBas.KEY_B_NAME };
    Cursor c = tdb.query(DatBas.DATABASE_TABLE_SETTINGS, columns, null, null, null, null,
                null);
    

    Instead get a reference to a valid SQLiteDatabase:

    SQLiteDatabase tdb = dbc.getDatabase();
    String[] columns = new String[] { DatBas.KEY_ROW_B_ID, DatBas.KEY_B_NAME };
    Cursor c = tdb.query(DatBas.DATABASE_TABLE_SETTINGS, columns, null, null, null, null,
                null);
    

    where getDatabase() is a method in your DatBas class like this:

    public SQliteDatabase getDatabase() {
       return tdb;
    }
    

    Also, remove the method getReadableDatabase() from your DatBas class.

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

Sidebar

Related Questions

I have two activities. In first I come to the second activity from first
I have two activities. The first one executes the second one. Intent i =
I have two activities, one is main and I have another activity called Test
Here's scenario: I have 2 activities and one service First activity is a landing
I have two activities. One activity has the main game and the other activity
Right now I have 3 tables, the first one for users, the second for
I have 2 activities. The first activity is an activity that parses JSON data
In my application I have several activities, the main screen has 4 buttons that
This is my situation. I have two activities: ONE and TWO. In TWO activity
Ive got two activities in the same application. the first one is with gui(main

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.