androidandroid-loader

Loader function showing error while returning Uri value


Loader function

@Override
public android.support.v4.content.Loader<Uri> onCreateLoader(int id, Bundle args) {

    DbLoader abc=new DbLoader(this,uri,values);

    return abc;
}

DbLoader function

public class DbLoader extends AsyncTaskLoader<Uri> {
Context context;
Uri uri;
ContentValues values;
public DbLoader(Context context, Uri uri, ContentValues values) {
    super(context);
    this.context=context;
    this.uri=uri;
    this.values=values;
}

@Override
public Uri loadInBackground() {
    Log.e("TAG","thread running");
  Uri  uriTemp=context.getContentResolver().insert(uri,values);
    return uriTemp;
}
}

I am getting error that I am returning data of wrong return type. I did the same with String while working with loading data from internet and it worked at that time. What can I do to remove this error?

Exact error message is

Incompatible types.
Required:
android.support.v4.content.Loader
<android.net.Uri>
Found:
com.example.asus.test_table.DbLoader

Solution

  • Looks like you are using the wrong AsyncTaskLoader. You want to

    import android.support.v4.content.AsyncTaskLoader; instead of

    import android.content.AsyncTaskLoader;. The former extends android.support.v4.content.Loader, the latter does not.