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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:13:48+00:00 2026-06-02T19:13:48+00:00

Good Evening, I have been trying to implement a simple Android(tm) application that utilizes

  • 0

Good Evening,

I have been trying to implement a simple Android(tm) application that utilizes Google Places(tm) API to determine local points of interest (such as restaurants and hotels), however I have been having quite a lot of trouble determining how to actually get started.

Resources I have already employed are as follows:

–The Google Places(tm) documentation

–An Android(tm) development blog hosted by Brain Buikema

-The Android(tm) developer documentation on asynchronous tasks

-Various other stackoverflow postings from individuals in similar circumstances

I was simply hoping for some guidance so that anyone in my situation could simply find this post and maybe then be forwarded to some extremely insightful resources.

Further, I feel that using Google searches to find resources is somewhat inefficient, are there other databases out there that programmers frequently utilize of which I am not aware? Any recommended literature?

TL;DR…

-I’m looking for some definitive guides for using the Places API, working with JSON objects and networking on the Android(tm) platform.

-I was hoping to be redirected to some useful sources others have found in the past.

-I have included my Main.java file below simply to provide context – I am not looking for answers 🙂


Code for the Main.java class that implements the Places API functionality:

        Button food = (Button) findViewById(R.id.button14);

        food.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) 
        {
            type = "restaurant";

            //Constructs the urlString
            if(useCurr)
                urlString = stringConstructor(myKey, lat, lon, radius, sensor, type);
            else
            {
                //Here, you must update the lat and lon values according to the location input by the user
                urlString = stringConstructor(myKey, lat, lon, radius, sensor, type);
            }



            //DO HTTPS REQUEST HERE
            urlString = "https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyAp24M3GU9V3kWrrezye8CyUrhtpToUhrs";

            Results res = new Results();

            JSONArray json = res.doInBackground(urlString);

            System.out.println(json);

        }
    });

Code for the Result class that handles the Asynchronous task:

private class Results extends AsyncTask<String, Integer, JSONArray>
{
    protected JSONArray doInBackground(String...params)
    {
        JSONArray output = null;

        try
        {
            try
            {
                url = new URL(params[0]);   
            }
            catch(MalformedURLException e)
            {
                System.out.println("URL formed incorrectly! (" + e + ")");
            }

            output = (JSONArray) url.getContent();
        }
        catch(Exception e)
        {
            System.out.println("Exception: " + e);
        }

        return output;
    }
}    

Currently receiveing an android.os.NetworkOnMainThreatException whenever I click on the “Food” button (described above) in the emulator.

Any advice is greatly welcomed, I am trying to build a really solid foundation on the Android platform.

  • 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-02T19:13:49+00:00Added an answer on June 2, 2026 at 7:13 pm

    You are not using AsyncTask in right way. android doc clearly says do’t call AsyncTask methods manually.you are calling doInBackground by creating object of AsyncTask change your code this way:

     btnclicl.setOnClickListener(new View.OnClickListener() {  
                    @Override  
                    public void onClick(View v) {  
                        Results  dTask = new Results();  
                        dTask.execute(urlString);  
                    }  
                });  
    
        class Results  extends AsyncTask<Integer, Integer, String>{  
    
                @Override  
            protected void onPostExecute(JSONObject json) {  
                Log.v("json", json);
                super.onPostExecute(json); 
            }  
            @Override  
            protected JSONObject doInBackground(String... params) { 
                JSONObject strtemp=null;            
              HttpClient httpclient = new DefaultHttpClient();
        // Prepare a request object
        HttpGet httpget = new HttpGet(urlString); 
        // Execute the request
        HttpResponse response;
        JSONObject json = new JSONObject();
        try {
            response = httpclient.execute(httpget);
    
            HttpEntity entity = response.getEntity();
    
            if (entity != null) {
    
                // A Simple JSON Response Read
                InputStream instream = entity.getContent();
                String result= convertStreamToString(instream);
    
                json=new JSONObject(result);
    
                instream.close();
            }
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return json;
            }  
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening, I have been trying to wrap my head about this, below, code
Good evening ladies and gentlemen, I have a problem with Java Swing that I
Good evening, In my app that I'm currently developing, I have a class that
Good evening all, I've been working on an MD5 tool in C# that takes
Good evening I have a JTable that I built with a TableModel how to
Good evening, i need to know how can i have one .h file that
Good evening, I am currently developing an application for android using phonegap and sencha
Good evening, I am tired and have been fighting with this for hours. I
Good Evening, The problem is that i have both xcode 3.2 and xcode 4
Good evening, here is what I am trying to achieve, I currently have a

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.