1

I am implementing Custom Content Provider and the problem is when i insert any value it gives me exception

Attempt to invoke virtual method 'android.net.Uri$Builder android.net.Uri.buildUpon()' on a null object reference

my code for inserting the value is

    public final static Uri uri = "content://com.test.myproject.Models.myProvider/users";
    ContentValues updateValues = new ContentValues(0);
    updateValues.put("name","ali");
    updateValues.put("description","basic user");
    updateValues.put("status",0);
    context.getContentResolver().insert(uri, updateValues);`

If you need more info/code them lemme know.
Kindly help. Thanks in advance

Umer Asim
  • 33
  • 6

1 Answers1

0

Did you try with the Uri.Builder class ?

Builder builder = new Uri.Builder(); 
builder.scheme("content"); 
builder.authority("com.test.myproject.Models.myProvider"); 
builder.appendPath("users"); 

//...

context.getContentResolver().insert(builder.build(), updateValues);

See documentation

ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77