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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:00:25+00:00 2026-05-24T11:00:25+00:00

I built this DBmanager class for convenience, but the getAllRows() method is causing a

  • 0

I built this DBmanager class for convenience, but the getAllRows() method is causing a fuss about nullpointerexceptions. I simply want to use it to get all rows without any filtering. What am I doing wrong?

    package com.com.com;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBManager {

    private SQLiteDatabase db; // a reference to the database manager class.
    private final String DB_NAME = "calls.db"; // the name of our database
    private final int DB_VERSION = 1; // the version of the database

    // the names for our database columns
    private final String TABLE_NAME = "calls";
    private final String TABLE_ROW_ID = "id";
    public final String TABLE_ROW_ONE = "number";
    public final String TABLE_ROW_TWO = "date";

    public void addRow(String rowStringOne, String rowStringTwo){
        // this is a key value pair holder used by android's SQLite functions
        ContentValues values = new ContentValues();

        // this is how you add a value to a ContentValues object
        // we are passing in a key string and a value string each time
        values.put(TABLE_ROW_ONE, rowStringOne);
        values.put(TABLE_ROW_TWO, rowStringTwo);

        // ask the database object to insert the new data 
        try
        {
            db.insert(TABLE_NAME, null, values);
        }
        catch(Exception e)
        {
            Log.e("DB ERROR", e.toString()); // prints the error message to the log
            e.printStackTrace(); // prints the stack trace to the log
        }
    }

    public Cursor getAllRows(){
        Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null, null);
        //Cursor cursor = db.query(TABLE_NAME, new String[] { TABLE_ROW_ID, TABLE_ROW_ONE, TABLE_ROW_TWO }, null, null, null, null, null);
        return cursor;
    }

    /*
     * SQLiteHelper Class
     */
    private class CustomHelper extends SQLiteOpenHelper{

        public CustomHelper(Context context){
            super(context, DB_NAME, null, DB_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db){
            // the SQLite query string that will create our 3 column database table.
            String newTableQueryString =    
                    "create table " +
                            TABLE_NAME +
                            " (" +
                            TABLE_ROW_ID + " integer primary key autoincrement not null," +
                            TABLE_ROW_ONE + " text," +
                            TABLE_ROW_TWO + " text" +
                            ");";

            // execute the query string to the database.
            db.execSQL(newTableQueryString);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
            // NOTHING TO DO HERE. THIS IS THE ORIGINAL DATABASE VERSION.
            // OTHERWISE, YOU WOULD SPECIFIY HOW TO UPGRADE THE DATABASE
            // FROM OLDER VERSIONS.
        }

    }

}
  • 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-24T11:00:26+00:00Added an answer on May 24, 2026 at 11:00 am

    Well, ‘fuss about nullpointerexceptions’ is hardly a detailed description of your problem. Posting the stacktrace would help. In your case you are not initializing your db variable.
    You need to call getWritableDatabase() to do so.

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

Sidebar

Related Questions

I built this method to find the longest word in an array, but I'm
I built up this regex at http://regextester.com to parse YSOD but VS is complaining
I have this string that has illegal chars that I want to remove but
I've built this little script that searches a table in my database, but for
I built this class to work with PDO, to make SQL queries 'easier' and
I built this site a couple of years back and but am now in
I've built this actionPerformed method so that it reads a string I pass to
I've built this model which contains a generic foreign key: class MyModel(models.Model): content_type =
So, I've built this navigation bar so far and I'm curious if it's even
I've got a JavaScript object, built this way: function foo() { this.length = 0;

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.