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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:06:49+00:00 2026-06-02T18:06:49+00:00

I have a strange issue with AsyncTask. I’m using an AsyncTask to load data

  • 0

I have a strange issue with AsyncTask. I’m using an AsyncTask to load data from my website and create a ListView with theses datas. I set a listener to each item, when i click on an item i start a new activity.

But when my new activity is loaded, the old asynctask (from the first activity) reload and makes my application crash. (Because it tries to modify a ListView which don’t exist anymore)

I tested the status of my AsyncTask and it never finish (always returning RUNNING but onPostExecute() is done)

package com.wglxy.example.dash1;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.os.AsyncTask;
import android.os.Bundle;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SimpleAdapter;


public class F1Activity extends DashboardActivity {


@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView (R.layout.activity_f2);
    setTitleFromActivityLabel (R.id.title_text);

    // Je démarre l'AsyncTask qui charge les interventions
    getInterventionListing Listing = new getInterventionListing();
    Listing.execute();      
}


private class getInterventionListing extends AsyncTask<Integer, Integer, ArrayList<HashMap<String, String>>>
{
    private ProgressDialog dialog;


    @Override
    protected void onPreExecute()
    {
        // Dialog qui s'affiche durant l'AsyncTask
        dialog = ProgressDialog.show(F1Activity.this, "Chargement", "Chargement des données",true,true,new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                dialog.dismiss();
                cancel(true);
            }});
    }

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(Integer... params) 
    {
        InputStream is = null;
        String result = "";
        String problemes = "";
        String prenom = "";
        String strURL = "http://monsiteweb.com/fichier.php";
        ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();


        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("listing_intervention",""));

        // Requête HTTP
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(strURL);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        }catch(Exception e){
            Log.e("log_tag", "Error in http connection " + e.toString());
        }


        HashMap<String, String> map;


        // Convertion de la requête en string
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
        }catch(Exception e){
            Log.e("log_tag", "Error converting result " + e.toString());
        }

        // Parse des données JSON
        try{
            JSONArray jArray = new JSONArray(result);

            for(int i=0;i<jArray.length();i++){
                JSONObject json_data = jArray.getJSONObject(i);
                if (json_data.getString("problemes") != "null")
                    problemes = json_data.getString("problemes");
                if (json_data.getString("prenom") != "null")
                    prenom = json_data.getString("prenom");

                map = new HashMap<String, String>();
                map.put("titre", "N°" + json_data.getInt("id_intervention") + " : " + json_data.getString("nom") + " " + prenom);
                map.put("description", problemes);
                map.put("id_intervention", json_data.getString("id_intervention"));
                map.put("id_client", json_data.getString("id_client"));
                if (json_data.getInt("statut") == 0) 
                {
                    map.put("img", String.valueOf(R.drawable.onwork));
                }
                else if (json_data.getInt("statut") == 2) 
                {
                    map.put("img", String.valueOf(R.drawable.onwait));
                }
                else if (json_data.getInt("statut") == 6) 
                {
                    map.put("img", String.valueOf(R.drawable.home));
                }
                else
                {
                    map.put("img", String.valueOf(R.drawable.other));
                }

                    listItem.add(map);

            }

        }catch(JSONException e){
            Log.e("log_tag", "Error parsing data " + e.toString());
        }
        return listItem;

    }


    @Override
    protected void onPostExecute(ArrayList<HashMap<String, String>> listItem)
    {
        ListView maListViewPerso = (ListView) findViewById(R.id.listviewperso);
        SimpleAdapter mSchedule = new SimpleAdapter (F1Activity.this, listItem, R.layout.listview,
                new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
        maListViewPerso.setAdapter(mSchedule);


        maListViewPerso.setOnItemClickListener(new OnItemClickListener() {              
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                ListView maListViewPerso = (ListView) findViewById(R.id.listviewperso);
                HashMap<String, String> items_loaded = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
                Intent defineIntent = new Intent(F1Activity.this, Details_intervention.class);
                Bundle objetbundle = new Bundle();
                objetbundle .putString("id_intervention",items_loaded.get("id_intervention").toString());
                objetbundle .putString("id_client",items_loaded.get("id_client").toString());
                defineIntent.putExtras(objetbundle );
                F1Activity.this.startActivity(defineIntent);
            }
        });

        dialog.dismiss();
    }



}

}

–

03-03 16:58:27.300: W/dalvikvm(656): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
03-03 16:58:27.320: E/AndroidRuntime(656): FATAL EXCEPTION: main
03-03 16:58:27.320: E/AndroidRuntime(656): java.lang.NullPointerException
03-03 16:58:27.320: E/AndroidRuntime(656):  at com.wglxy.example.dash1.F1Activity$getInterventionListing.onPostExecute(F1Activity.java:164)
03-03 16:58:27.320: E/AndroidRuntime(656):  at com.wglxy.example.dash1.F1Activity$getInterventionListing.onPostExecute(F1Activity.java:1)
03-03 16:58:27.320: E/AndroidRuntime(656):  at android.os.AsyncTask.finish(AsyncTask.java:602)
  • 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-02T18:06:52+00:00Added an answer on June 2, 2026 at 6:06 pm

    If you still need assistance…

    Can you post the code for the Activity you are calling through onClick — Details_intervention.class ?

    A couple notes:

    1. You can start the activity by just having startActivity(defineIntent), you dont need F1Activity.this.

    2. Not to be picky, but you are breaking some java coding conventions throughout. Although it wont hurt the app, some things are not standard and just weird at first glance: An example is private class getInterventionListing – Classes should start with a capital letter and the preface “get” and “set” are used for methods only. So private class DownloadInterventionListing would be better.

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

Sidebar

Related Questions

I have a strange issue from a client in that our code, which they
I have a strange issue setting data inside an active record.. When I attempt
I have a strange issue with an Asp.NET MVC application. Using Asp.NET MVC 3
We have a strange issue with running an Facebook IFrame application (using MVC 2).
I have a strange issue using HttpWebRequest, I'm trying to post a string to
I have a strange issue trying to run the Facebook iOS SDK DemoApp (from
I have this strange issue with my web app. You see, I'm using jQuery
I have encountered strange issue with lists in F#. I am using XamlXmlReader to
I have a strange issue with bluetooth socket. If I create socket and later
I have some strange issue using jQuery Validation plugin. Firs of all here is

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.