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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:16:17+00:00 2026-05-20T05:16:17+00:00

I have a ContentProvider named GeneralDataProvider . Which calls @Override public boolean onCreate() {

  • 0

I have a ContentProvider named GeneralDataProvider. Which calls

@Override
public boolean onCreate() {
    mDatabaseOpenHelper = new DatabaseOpenHelper(getContext());
    return true;
}

Which looks like:

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

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.e("DataBaseOpenHelper", "onCreate()");
        //The columns we'll include in the dictionary table
        //db.execSQL("CREATE TABLE general " + 
        // .. and more
    }
}

The problem

This works fine as long as I run managedQuery(…) inside an Activity, but when i try to execute the following code in a thread, I get a NullPointerException.

 public class SyncManager extends Thread {

         @Override
         public void run() {
            mIntent = new Intent();
            mIntent.setData(GeneralDataColumns.CONTENT_URI);
            GeneralDataProvider generalProvider = new GeneralDataProvider();
            mCursor = generalProvider.query(mIntent.getData(), GENERAL_PROJECTION, selection, null,
            GeneralDataColumns.DEFAULT_SORT_ORDER);
     }
 }

Which is executed from my main activity as such

    mSyncManager = new SyncManager();
    mSyncManager.start();

After digging deeper, it turns out that what causes the NullPointerException is the following line, inside GeneralDataProvider.query().

       SQLiteDatabase db = mDatabaseOpenHelper.getReadableDatabase();

Since mDatabaseOpenHelper is null.

Am I using my ContentProvider in an incorrect manner?

What I have tried:
Added ‘synchronized’ to the query()-method inside my GeneralDataProvider

  • 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-20T05:16:18+00:00Added an answer on May 20, 2026 at 5:16 am

    Turned out I was wrong.

    The problem is that query() didn’t work as I expected it to. I had to send a ContentResolver to my SyncManager-class as such

        mSyncManager = new SyncManager(getContentResolver());
        mSyncManager.start();
    

    And then use that ContentResolver when performing the actual query.

        public SyncManager(ContentResolver context) {
            mContentResolver = context;
        }
    
        @Override
        public void run() {
    
           // General data
           mIntent = new Intent();
           mIntent.setData(GeneralDataColumns.CONTENT_URI);
           mCursor = mContentResolver.query(mIntent.getData(), GENERAL_PROJECTION, selection, null, GeneralDataColumns.DEFAULT_SORT_ORDER);
       }
    

    This solved all of my problems!

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

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have my own custom Content Provider that loads a database which contains the
If I call to a ContentProvider from a Activity, which thread is ContentProvider running
I have a new web app that is packaged as a WAR as part
I have found this example on StackOverflow: var people = new List<Person> { new
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
I have some large files (images and video) which I need to store in
I have application, which downloads data from internet and is supposed to write it
I have a normal SQLite database in my app, managed through my own ContentProvider

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.