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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:07:56+00:00 2026-06-06T06:07:56+00:00

I am attempting to test the update() method of my custom content provider. I

  • 0

I am attempting to test the update() method of my custom content provider. I receive a null pointer exception due to the getContext() method call within the update() method being null. To alleviate this issue I have attempted implementing Why does AndroidTestCase.getContext().getApplicationContext() return null? to no avail. My test class looks like the following:

 public class AddressContentProviderTest extends ProviderTestCase2<AddressContentProvider> {

    public AddressContentProviderTest() {
    super(AddressContentProvider.class, AddressContentProvider.class.getName());
}

protected void setUp() throws Exception {
    super.setUp();
}
    public void testInsert() {
         Uri CONTENT_URI = Uri.parse("content://" + AddressContentProvider.AUTHORITY + "/address");
         AddressContentProvider addressContentProvider = new AddressContentProvider();
         ContentValues initialValues = new ContentValues();
         boolean isException = false;
         Uri returnURI = null;
         initialValues.put("country", "test");
         initialValues.put("region", "test");
         initialValues.put("city", "test");
         initialValues.put("state", "FL");
         initialValues.put("zip", "90210");
         initialValues.put("province", "test");
         initialValues.put("geo_location_id", "");

          returnURI = addressContentProvider.insert(CONTENT_URI, initialValues);

     assertTrue(returnURI != null);

}

The insert method looks like the following:

    @Override
    public int update(Uri uri, ContentValues values, String where, String[]  whereArgs) {
           SQLiteDatabase db =dbHelper.getWritableDatabase();
           int count;

          switch (sUriMatcher.match(uri)) {
            case ADDRESS:
                count = db.update(ADDRESS_TABLE_NAME, values, where, whereArgs);
                break;
            default:
         throw new IllegalArgumentException("Unknown URI " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}

I’m running my tests using Android 2.3.3 on Platform 10.

  • 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-06T06:07:58+00:00Added an answer on June 6, 2026 at 6:07 am

    So the answer to the problem was to call the getProvider(); method. This gives me access to the AddressContentProvider within the thread of execution;

        public void testInsert() {
            Uri CONTENT_URI = Uri.parse("content://" + AddressContentProvider.AUTHORITY + "/address");
            AddressContentProvider addressContentProvider = getProvider();
            ContentValues initialValues = new ContentValues();
        //Uri returnURI = null;
            initialValues.put("country", "USA");
            initialValues.put("region", "test");
            initialValues.put("city", "Jacksonville");
            initialValues.put("state", "FL");
            initialValues.put("zip", "32258");
            initialValues.put("province", "test");
            initialValues.put("geo_location_id", "");
            Uri returnURI = addressContentProvider.insert(CONTENT_URI, initialValues);
            assertTrue(returnURI != null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I am attempting to use this custom extension to perform an entity update.
I'm attempting to call a method written in C++/CLI from C#. The C++/CLI code
In our C# code, we already test if a variable is null before attempting
I am attempting to call a website root by using a PHP function within
I'm using QTP and QC 11 and am attempting to update a custom field
I'm attempting to test interactions with a Nexus server that requires authentication for the
I am attempting to test user interaction with an off the shelf product. The
Attempting to implement a poor man's test of whether a process is still running
I'm attempting to register a GIS based dll on a test computer and I'm
When attempting to update value, these error are occuring, 02-09 11:37:53.573: ERROR/AndroidRuntime(4809): android.database.sqlite.SQLiteException: attempt

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.