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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:02:37+00:00 2026-05-25T15:02:37+00:00

I’ve got this problem. I’ve got a ListActivity, in which i want to inport

  • 0

I’ve got this problem. I’ve got a ListActivity, in which i want to inport all my Database entries, which I afterwards want to see on my List.

Now there’s a Nullpointer exception Problem, when i get all Data from my Table. You see it at Step2.

Here’s the Code of the ListActivity:

package de.retowaelchli.filterit.stats;


import de.retowaelchli.filterit.database.ADFilterDBAdapter;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;



public class CreatedADFilters extends ListActivity {

    //Variablen deklaration
    private ADFilterDBAdapter mDbHelper;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        //Hier wir die Datenbank aufgerufen
        mDbHelper = new ADFilterDBAdapter(this);
        mDbHelper.open();
        System.out.println("STEP1"); //Until here it works



        Cursor c = mDbHelper.getAllADFilter();
        startManagingCursor(c);
        System.out.println("STEP2"); //Here's the problem I don't get.


    }

    }

So and here’s the Code-Part of my DB-Adapter:

    public Cursor getAllADFilter() {

        return this.mDb.query(DATABASE_TABLE, new String[] { ROW_ID,
                NAME, KEYWORD, CACHE }, null, null, null, null, null);
    }

I don’t get what I’m doing wrong, please gimme some advice.

Thank you in advance!

So here’s the whole DB-Adapter for this Table:

package de.retowaelchli.filterit.database;

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

public class ADFilterDBAdapter {

        public static final String ROW_ID = "_id";
        public static final String NAME = "name";
        public static final String KEYWORD = "keyword";
        public static final String CACHE = "cache";

        private static final String DATABASE_TABLE = "adfilter";

        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDb;

        private final Context mCtx;

        private static class DatabaseHelper extends SQLiteOpenHelper {

            DatabaseHelper(Context context) {
                super(context, DBAdapter.DATABASE_NAME, null, DBAdapter.DATABASE_VERSION);
            }

            @Override
            public void onCreate(SQLiteDatabase db) {
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            }
        }

        /**
         * Constructor - takes the context to allow the database to be
         * opened/created
         * 
         * @param ctx
         *            the Context within which to work
         */
        public ADFilterDBAdapter(Context ctx) {
            this.mCtx = ctx;
        }

        /**
         * Open the ADFilter database. If it cannot be opened, try to create a new
         * instance of the database. If it cannot be created, throw an exception to
         * signal the failure
         * 
         * @return this (self reference, allowing this to be chained in an
         *         initialization call)
         * @throws SQLException
         *             if the database could be neither opened or created
         */
        public ADFilterDBAdapter open() throws SQLException {
            this.mDbHelper = new DatabaseHelper(this.mCtx);
            this.mDb = this.mDbHelper.getWritableDatabase();
            return this;
        }

        /**
         * close return type: void
         */
        public void close() {
            this.mDbHelper.close();
        }

        /**
         * Create a new ADFilter. If the car is successfully created return the new
         * rowId for that ADFilter, otherwise return a -1 to indicate failure.
         * 
         * @param name
         * @param keyword
         * @param cache
         * @return rowId or -1 if failed
         */
        public long createADFilter(String name, String keyword, String cache){
            ContentValues initialValues = new ContentValues();
            initialValues.put(NAME, name);
            initialValues.put(KEYWORD, keyword);
            initialValues.put(CACHE, cache);
            return this.mDb.insert(DATABASE_TABLE, null, initialValues);
        }

        /**
         * Delete the ADFilter with the given rowId
         * 
         * @param rowId
         * @return true if deleted, false otherwise
         */
        public boolean deleteADFilter(long rowId) {

            return this.mDb.delete(DATABASE_TABLE, ROW_ID + "=" + rowId, null) > 0; //$NON-NLS-1$
        }

        /**
         * Return a Cursor over the list of all ADFilter in the database
         * 
         * @return Cursor over all ADFilters
         */
        public Cursor getAllADFilter() {

            return this.mDb.query(DATABASE_TABLE, new String[] { ROW_ID,
                    NAME, KEYWORD, CACHE }, null, null, null, null, null);
        }

        /**
         * Return a Cursor positioned at the ADFilter that matches the given rowId
         * @param rowId
         * @return Cursor positioned to matching ADFilter, if found
         * @throws SQLException if ADFilter could not be found/retrieved
         */
        public Cursor getADFilter(long rowId) throws SQLException {

            Cursor mCursor =

            this.mDb.query(true, DATABASE_TABLE, new String[] { ROW_ID, NAME,
                    KEYWORD, CACHE}, ROW_ID + "=" + rowId, null, null, null, null, null);
            if (mCursor != null) {
                mCursor.moveToFirst();
            }
            return mCursor;
        }

        /**
         * Update the ADFilter
         * 
         * @param rowId
         * @param name
         * @param keyword
         * @param cache
         * @return true if the note was successfully updated, false otherwise
         */
        public boolean updateADFilter(long rowId, String name, String keyword,
                String cache){
            ContentValues args = new ContentValues();
            args.put(NAME, name);
            args.put(KEYWORD, keyword);
            args.put(CACHE, cache);

            return this.mDb.update(DATABASE_TABLE, args, ROW_ID + "=" + rowId, null) >0; 
        }

    }

And here’s the global DB-Adapter:

package de.retowaelchli.filterit.database;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBAdapter {

    public static final String DATABASE_NAME = "filterit"; //$NON-NLS-1$

    public static final int DATABASE_VERSION = 1;

    public static final String CREATE_TABLE_ADFILTER =
       "create table adfilter (_id integer primary key autoincrement, " //$NON-NLS-1$
    + ADFilterDBAdapter.NAME+ " TEXT," //$NON-NLS-1$
    + ADFilterDBAdapter.KEYWORD+ " TEXT," //$NON-NLS-1$
    + ADFilterDBAdapter.CACHE+ " TEXT" + ");"; //$NON-NLS-1$ //$NON-NLS-2$

    private static final String CREATE_TABLE_SFILTER = "create table sfilter (_id integer primary key autoincrement, " //$NON-NLS-1$
    +SFilterDBAdapter.NAME+" TEXT," //$NON-NLS-1$
    +SFilterDBAdapter.KEYWORD+" TEXT," //$NON-NLS-1$
    +SFilterDBAdapter.COLOR+" TEXT,"//$NON-NLS-1$  //$NON-NLS-2$
    +SFilterDBAdapter.SMILEY+" TEXT"+ ");";

        private static final String CREATE_TABLE_ADMESSAGES = "create table admessages (_id integer primary key autoincrement, " //$NON-NLS-1$
    +ADMessagesDBAdapter.PHONENUMBER+" TEXT," //$NON-NLS-1$
    +ADMessagesDBAdapter.MESSAGE+" TEXT,"+ ");"; //$NON-NLS-1$  //$NON-NLS-2$


    private final Context context; 
    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    /**
     * Constructor
     * @param ctx
     */
    public DBAdapter(Context ctx)
    {
        this.context = ctx;
        this.DBHelper = new DatabaseHelper(this.context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            db.execSQL(CREATE_TABLE_ADFILTER);
            db.execSQL(CREATE_TABLE_SFILTER);
            db.execSQL(CREATE_TABLE_ADMESSAGES);           
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, 
        int newVersion) 
        {               
            // Adding any table mods to this guy here
        }
    } 

   /**
     * open the db
     * @return this
     * @throws SQLException
     * return type: DBAdapter
     */
    public DBAdapter open() throws SQLException 
    {
        this.db = this.DBHelper.getWritableDatabase();
        return this;
    }

    /**
     * close the db 
     * return type: void
     */
    public void close() 
    {
        this.DBHelper.close();
    }
}

I Hope that helps you out.. =)

  • 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-25T15:02:37+00:00Added an answer on May 25, 2026 at 3:02 pm

    As ingsaurabh noted, you may have nothing in DB.
    Just note, that Cursor should never be null even if result set is empty; just Cursor.getCount() shall return 0. Be sure to always do Cursor.moveToNext() to advance to first record in result set.
    We need your startManagingCursor method to get you answer.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.