Home » Android » java – AsyncTaskLoader Functions Error in android-Exceptionshub

java – AsyncTaskLoader Functions Error in android-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have a run error in my application the error is in (LoadManager.loaderCallbacks) give me this in picture below i have tried a lot to solve it but didn’t reach a solution for it yet .
what can i do to solve it !
thanks for helping ..

mainActivity:

package com.example.myapplication;

import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Loader;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements LoaderCallbacks<List<Info>> {

public static final String LOG_TAG = MainActivity .class.getName();
public  List<Info> earthquakes = new ArrayList<>() ;
EarthAdapter<Info> earthAdapter ;
public final String URL_NAME =  "https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&orderby=time&minmag=6&limit=10";
private static final int ID=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ListView earthquakeListView = (ListView) findViewById(R.id.list);
    earthAdapter = new EarthAdapter<>(this,new ArrayList<Info>());
    earthquakeListView.setAdapter(earthAdapter);
    earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Info info= earthAdapter.getItem(position);
            Uri uri = Uri.parse(info.getUrl());
            Intent intent = new Intent(Intent.ACTION_VIEW,uri);
            startActivity(intent);

        }
    });
    /*EarthquakeAsync earthquakeAsync = new EarthquakeAsync();
    earthquakeAsync.execute(URL_NAME);*/
    LoaderManager loaderManager =getLoaderManager();
    loaderManager.initLoader(ID,null,this);

}

@Override
public Loader<List<Info>> onCreateLoader(int id, Bundle args) {
    Log.e(LOG_TAG,"onCreateLoader");
    EarthquakeLoader earthquakeLoader =  new EarthquakeLoader(MainActivity.this,URL_NAME);
    return earthquakeLoader;
}

@Override
public void onLoadFinished(Loader<List<Info>> loader, java.util.List<Info> infos) {
    Log.e(LOG_TAG,"onLoadFinished");
    earthAdapter.clear();
    if (infos != null && !infos.isEmpty()) {
        earthAdapter.addAll(infos);
    }
}


@Override
public void onLoaderReset(Loader<List<Info>> loader) {
    Log.e(LOG_TAG,"onLoaderReset");
    earthAdapter.clear();
}

loader.java

    package com.example.myapplication;

import android.content.Context;
import android.support.annotation.Nullable;
import android.content.AsyncTaskLoader;
import android.util.Log;

import java.util.List;

class EarthquakeLoader extends AsyncTaskLoader<List<Info>> {
    static final String TAG_NAME=EarthquakeLoader.class.getName();
    String url;
    public EarthquakeLoader(Context context, String url) {
        super(context);
        this.url=url;
    }

@Nullable
@Override
public List<Info> loadInBackground() {
    Log.e(TAG_NAME,"loadInBackground");
    if (url!= null) {
        return null;
    }
    List<Info> earthquakes = QueryUtils.earthquakesAsync(url);
    return earthquakes;

}

@Override
protected void onStartLoading() {
    Log.e(TAG_NAME,"onStartLoading");
    forceLoad();
}
}

stacktrace:

02-18 17:44:52.744 1767-1775/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/networkstatistics.sqlite' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

02-18 17:44:52.794 1767-2060/com.google.android.gms D/AuthZenTransactionCache: Initialized cache in: /data/data/com.google.android.gms/files
02-18 17:44:52.794 1767-2060/com.google.android.gms D/AuthZenTransactionCache: Clearing transaction cache
02-18 17:44:53.054 1767-2019/com.google.android.gms I/FA-SVC: App measurement is starting up, version: 9256
02-18 17:44:53.054 1767-2019/com.google.android.gms I/FA-SVC: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
02-18 17:44:53.154 1767-2130/com.google.android.gms V/FA-SVC: Update service enabled state to: 1
02-18 17:44:53.154 1767-2130/com.google.android.gms I/FA-SVC: This instance being marked as an uploader

Loader used AsyncTaskLoader

How to&Answers: