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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:51:42+00:00 2026-06-16T03:51:42+00:00

I have AsyncTask.class in here i parse json and return List, and in postExecute

  • 0

I have AsyncTask.class in here i parse json and return List, and in postExecute i need add this List to my Adapter and notify to change, but LogCat give Error, how i can fix this?

My Adapter have public state, why i cant add to him results?

 FATAL EXCEPTION: main
 java.lang.NullPointerException
    at com.gazetaimage.LoadTask.onPostExecute(LoadTask.java:84)
    at com.gazetaimage.LoadTask.onPostExecute(LoadTask.java:1)
    at android.os.AsyncTask.finish(AsyncTask.java:631)
    at android.os.AsyncTask.access$600(AsyncTask.java:177)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5191)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
    at dalvik.system.NativeStart.main(Native Method)

LoadTask.java

public class LoadTask extends AsyncTask<Void, Void, List<String>> {

    MainActivity main = new MainActivity();

    private int page = 1;

    public int addPage(int i){
        return page = i;
    }

    @Override
    protected List<String> doInBackground(Void... params) {

        InputStream ips = null; 
        JSONObject jsonObj = null;
        String json = "";       
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpResponse response = httpClient.execute(new HttpPost("http://iapp.gazeta.uz/fotolenta?page="+page)); 
            ips = response.getEntity().getContent();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader bufff = new BufferedReader(new InputStreamReader(ips, "UTF-8"));
            StringBuilder sb = new StringBuilder();
            String line = null;

            while ((line = bufff.readLine()) != null){
                sb.append(line + "\n");                 
            }
            ips.close();
            json = sb.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            jsonObj = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if(jsonObj != null){

        JSONArray array = jsonObj.optJSONArray("img_list"); 
            for (int i = 0; i < array.length(); i++) {
                main.thumbs.add(array.optJSONObject(i).optString("thumbnail"));
            }
        }
        else{
            Log.d("Log", "Nullll");
        }

        return main.thumbs;
    }

    @Override
    protected void onPostExecute(List<String> result) {
        if (result != null){
            main.adapter.add(result);// HERE I HAVE Error 84
        }

    }
}
  • 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-16T03:51:44+00:00Added an answer on June 16, 2026 at 3:51 am

    You cannot create an instance of the activity inside the task, and expect it will be the same activity running..

    Instead, You can create interface, pass it to AsyncTask (in constructor), and then call method in onPostExecute

    For example:

    Your interface:

    public interface OnTaskCompleted{
        void onTaskCompleted(values);
    }
    

    Your Activity:

    public YourActivity implements OnTaskCompleted{
        //your Activity
        YourTask  task = new YourTask(this); // here is the initalization code for your asyncTask
    }
    

    And your AsyncTask:

    public YourTask extends AsyncTask<Object,Object,Object>{ //change Object to required type
        private OnTaskCompleted listener;
    
        public YourTask(OnTaskCompleted listener){
            this.listener=listener;
        }
    
        //required methods
    
        protected void onPostExecute(Object o){
            //your stuff
            listener.onTaskCompleted(values);
        }
    }
    

    taken from https://stackoverflow.com/a/9963705/1434631

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

Sidebar

Related Questions

I have this class public final class AsyncTaskManager<T extends AsyncTask<?, ?, ?> & IProgressTrackerTask
I have the following asynctask class which is not inside the activity. In the
i have a question regarding the AsyncTask class in android, and why it is
i have a class extends asynctask private class taskMK extends AsyncTask<Void,Void,JSONObject>{ String url; JSONObject
I have an AsyncTask with a textview loaded in the class so it looks
I have a class that extends AsyncTask , which fetches the gps cordinates from
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have an Activity class which has an attribute that references an AsyncTask instance
I am trying to create downloading progress. I have my class which extends AsyncTask:
I have an Activity Class with an inner protected class that extends AsyncTask. I

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.