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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:59:59+00:00 2026-06-05T15:59:59+00:00

i have a class extends asynctask private class taskMK extends AsyncTask<Void,Void,JSONObject>{ String url; JSONObject

  • 0

i have a class extends asynctask

private class taskMK extends AsyncTask<Void,Void,JSONObject>{
        String url;
        JSONObject json;
        public taskMK(String tr){
            this.url = tr;
        }
        @Override
        protected JSONObject doInBackground(Void... params) {
            JSONParser jsonParser = new JSONParser();
            JSONObject json = jsonParser.getJSONFromURL(url);
            return json;
        }

        @Override
        protected void onPostExecute(JSONObject result) {
            this.json = result;
        }

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
        }
        public JSONObject getkq(){
            return this.json;
        }

    }

In activity

String url = "https://maps.googleapis.com/maps/api/place/search/json?location="+lat+"%2C"+lng+"&name=atm&radius="+bk+"&sensor=false&key=AIzaSyCxaZYo1zJ_QxuNcp5dL5P0xm5XvIJPXRw";
taskMK mk = new taskMK(url);
mk.execute();
JSONObject json = mk.getkq();

I intend to put this code in asynctask class but i get error “Can’t create handler inside thread that has not called Looper.prepare()” …. Actually, I don’t know how to do solved this.

    Double lat = loc.getLatitude();
    Double lng = loc.getLongitude();
    String url = "https://maps.googleapis.com/maps/api/place/search/json?location="+lat+"%2C"+lng+"&name=atm&radius="+bk+"&sensor=false&key=AIzaSyCxaZYo1zJ_QxuNcp5dL5P0xm5XvIJPXRw";

    JSONParser jsonParser = new JSONParser();
    JSONObject json = jsonParser.getJSONFromURL(url);
    marker=getResources().getDrawable(R.drawable.hoe);
    itemizedOverlay = new MarkerATM(marker, mapView);
    int i=0;
    try{
        JSONArray array_atm = json.getJSONArray("results");
        for(i=0;i<array_atm.length();i++){
            JSONObject c = array_atm.getJSONObject(i);
            String atm_name = c.getString("name");
            String atm_address = c.getString("vicinity");

            JSONObject geometry  = c.getJSONObject("geometry");
            JSONObject location = geometry.getJSONObject("location");
            String atm_lat = location.getString("lat");
            String atm_lng = location.getString("lng");

            Double _lat = Double.parseDouble(atm_lat)*1E6;
            Double _lng = Double.parseDouble(atm_lng)*1E6;

            GeoPoint myPoint = new GeoPoint(_lat.intValue(), _lng.intValue());
            OverlayItem overlayItem = new OverlayItem(myPoint, atm_name, atm_address);
            itemizedOverlay.addOverlay(overlayItem);                            
        }
    }   catch(JSONException e){
        e.printStackTrace();
    }
    mapOverlays.add(itemizedOverlay);

i want to get data from taskMK but data always return null … how to do i solved my problem 🙁 .. sorry i use english not good.

  • 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-05T16:00:01+00:00Added an answer on June 5, 2026 at 4:00 pm

    Rather than using getkq() in the taskMK class you can have a setkq() in the activity class which is executing the asyncTask. So use the following:

    private class taskMK extends AsyncTask<Void,Void,JSONObject>{
        String url;
        JSONObject json;
        MyActivityClassObject obj;
    
        public taskMK(String tr, MyActivityClassObject obj){
            this.url = tr;
            this.obj = obj;
        }
        @Override
        protected JSONObject doInBackground(Void... params) {
            JSONParser jsonParser = new JSONParser();
            JSONObject json = jsonParser.getJSONFromURL(url);
            return json;
        }
    
        @Override
        protected void onPostExecute(JSONObject result) {
            this.obj.setkq(result);
        }
    
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
        }
    }
    

    And in your activity class you can have this function:

    public void setkq(JSONObject obj){
            //Add your parsing logic here
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Override protected
I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
i have this class: public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { ImageFromWeb ifw;
I have this AsyncTask: private class GetMyFlights extends AsyncTask<String, Void, Integer> { private ProgressDialog
I have this code so far: private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
I have created an asynchronous task like this: private class LongOperationcheckall extends AsyncTask<String, String,
I have classic AsyncTask to load image: private class DownloadImageTask extends AsyncTask<String,Void,Bitmap> { Bitmap
I have a class which extends AsyncTask public class SendJSONArray2Server extends AsyncTask<String, Void, HttpResponse>
This is what I have: class Calendar extends CI_Controller { public $extension; function __construct()
I have class where I draw image. This is code: public class CanvasdrawActivity extends

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.