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

  • Home
  • SEARCH
  • 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 8777299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:14:51+00:00 2026-06-13T19:14:51+00:00

I am very new to android Google maps i write the following program for

  • 0

I am very new to android Google maps i write the following program for displaying the auto sugesstion in the android when i am type the text in the Autocomplete text box it is going the input to the url but the out put is not showing in the program .please see once and let me know where i am doing the mistake.

   ExampleApp.java
package com.example.exampleapp;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater.Filter;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import android.widget.Filterable;
import android.widget.Toast;

public class ExampleApp extends Activity implements OnItemClickListener{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        AutoCompleteTextView autoCompView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
        autoCompView.setAdapter(new PlacesAutoCompleteAdapter(this, R.layout.list_item));
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        String str = (String) arg0.getItemAtPosition(arg2);
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }


}
class PlacesAutoCompleteAdapter extends ArrayAdapter<String> implements Filterable {
    private ArrayList<String> resultList;

    public PlacesAutoCompleteAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }
    private static final String PLACES_API_BASE = "https://maps.googleapis.com/maps/api/place";
    private static final String TYPE_AUTOCOMPLETE = "/autocomplete";
    private static final String OUT_JSON = "/json";

    private static final String API_KEY = "";
    @Override
    public int getCount() {
        return resultList.size();
    }

    @Override
    public String getItem(int index) {
        return resultList.get(index);
    }

    @Override
    public android.widget.Filter getFilter() {
        Filter filter = new Filter() {
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults filterResults = new FilterResults();
                if (constraint != null) {
                    // Retrieve the autocomplete results.
                    resultList = autocomplete(constraint.toString());

                    // Assign the data to the FilterResults
                 //   filterResults.values = resultList;
                  //  filterResults.count = resultList.size();
                }
                return filterResults;
            }

            private ArrayList<String> autocomplete(String input) {
                ArrayList<String> resultList = null;

                HttpURLConnection conn = null;
                StringBuilder jsonResults = new StringBuilder();
                try {
                    StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
                    sb.append("?sensor=false&key=" + API_KEY);
                    sb.append("&components=country:uk");
                    sb.append("&input=" + URLEncoder.encode(input, "utf8"));

                    URL url = new URL(sb.toString());
                    conn = (HttpURLConnection) url.openConnection();
                    InputStreamReader in = new InputStreamReader(conn.getInputStream());

                    // Load the results into a StringBuilder
                    int read;
                    char[] buff = new char[1024];
                    while ((read = in.read(buff)) != -1) {
                        jsonResults.append(buff, 0, read);
                    }
                } catch (MalformedURLException e) {
                   // Log.e(LOG_TAG, "Error processing Places API URL", e);
                    return resultList;
                } catch (IOException e) {
                    //Log.e(LOG_TAG, "Error connecting to Places API", e);
                    return resultList;
                } finally {
                    if (conn != null) {
                        conn.disconnect();
                    }
                }

                try {
                    // Create a JSON object hierarchy from the results
                    JSONObject jsonObj = new JSONObject(jsonResults.toString());
                    JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");

                    // Extract the Place descriptions from the results
                    resultList = new ArrayList<String>(predsJsonArray.length());
                    for (int i = 0; i < predsJsonArray.length(); i++) {
                        resultList.add(predsJsonArray.getJSONObject(i).getString("description"));
                    }
                } catch (JSONException e) {
                   // Log.e(LOG_TAG, "Cannot process JSON results", e);
                }

                return resultList;
            }
            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null) {
                    notifyDataSetChanged();
                }
                else {
                    notifyDataSetInvalidated();
                }
            }

            @Override
            public boolean onLoadClass(Class arg0) {
                // TODO Auto-generated method stub
                return false;
            }};
        return (android.widget.Filter) filter;
    }
}

FilterResults.java

package com.example.exampleapp;

import java.util.ArrayList;

public class FilterResults {

    protected ArrayList<String> values;
    protected int count;

}


i write the above code but the application closed .please see once and let me know where i am doing mistake in the above code ?
Thanks in Advance..........
  • 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-13T19:14:52+00:00Added an answer on June 13, 2026 at 7:14 pm

    Here is the Code Snippet Which i have Used when i have similar problem. i give you one suggestion that D’nt put your whole code in only single java file. Make the separate methods/class for each different task you are using in your code. it will help you easier to trace it.

    here is my PlacesAutoCompleteAdapter.java File.

    package com.inukshk.adapter;
    
    import java.util.ArrayList;
    
    import android.content.Context;
    import android.widget.ArrayAdapter;
    import android.widget.Filter;
    import android.widget.Filterable;
    
    import com.inukshk.CreateInukshk.CreateInukshk;
    
    public class PlacesAutoCompleteAdapter extends ArrayAdapter<String> implements
            Filterable {
        private ArrayList<String> resultList;
    
        public PlacesAutoCompleteAdapter(Context context, int textViewResourceId) {
            super(context, textViewResourceId);
        }
    
        @Override
        public int getCount() {
            return resultList.size();
        }
    
        @Override
        public String getItem(int index) {
            return resultList.get(index);
        }
    
        @Override
        public Filter getFilter() {
            Filter filter = new Filter() {
                @Override
                protected FilterResults performFiltering(CharSequence constraint) {
                    FilterResults filterResults = new FilterResults();
                    if (constraint != null) {
                        // Retrieve the autocomplete results.
    
                        resultList = CreateInukshk.autocomplete(constraint
                                .toString());
    
                        // Assign the data to the FilterResults
                        filterResults.values = resultList;
                        filterResults.count = resultList.size();
                    }
                    return filterResults;
                }
    
                @Override
                protected void publishResults(CharSequence constraint,
                        FilterResults results) {
                    if (results != null && results.count > 0) {
                        notifyDataSetChanged();
                    } else {
                        notifyDataSetInvalidated();
                    }
                }
            };
            return filter;
        }
    }
    

    here is What you have to do inside OnCreate() of your activity.

    autoCompView = (AutoCompleteTextView) findViewById(R.id.editloc);
            autoCompView.setAdapter(new PlacesAutoCompleteAdapter(this,
                    R.layout.list_item));
    

    here are the static Strings i have used in app.

    private static final String PLACES_API_BASE = "https://maps.googleapis.com/maps/api/place";
        private static final String TYPE_AUTOCOMPLETE = "/autocomplete";
        private static final String OUT_JSON = "/json";
        private static final String API_KEY = "YOUR API KEY";
    

    and Finally here is the Method that you will use in Adapter.

    public static ArrayList<String> autocomplete(String input) {
    
            ArrayList<String> resultList = null;
    
            HttpURLConnection conn = null;
            StringBuilder jsonResults = new StringBuilder();
            try {
                StringBuilder sb = new StringBuilder(PLACES_API_BASE
                        + TYPE_AUTOCOMPLETE + OUT_JSON);
                sb.append("?sensor=false&key=" + API_KEY);
                // sb.append("&components=country:uk");
                sb.append("&input=" + URLEncoder.encode(input, "utf8"));
    
                URL url = new URL(sb.toString());
                conn = (HttpURLConnection) url.openConnection();
                InputStreamReader in = new InputStreamReader(conn.getInputStream());
    
                // Load the results into a StringBuilder
                int read;
                char[] buff = new char[1024];
                while ((read = in.read(buff)) != -1) {
                    jsonResults.append(buff, 0, read);
                }
            } catch (MalformedURLException e) {
                Log.e(TAG, "Error processing Places API URL", e);
                return resultList;
            } catch (IOException e) {
                Log.e(TAG, "Error connecting to Places API", e);
                return resultList;
            } finally {
                if (conn != null) {
                    conn.disconnect();
                }
            }
    
            try {
                // Create a JSON object hierarchy from the results
                JSONObject jsonObj = new JSONObject(jsonResults.toString());
                JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");
    
                // Extract the Place descriptions from the results
                resultList = new ArrayList<String>(predsJsonArray.length());
                for (int i = 0; i < predsJsonArray.length(); i++) {
                    resultList.add(predsJsonArray.getJSONObject(i).getString(
                            "description"));
                }
    
            } catch (JSONException e) {
                Log.e(TAG, "Cannot process JSON results", e);
            }
    
            return resultList;
        }
    

    EDITED :

    i guess you have specified the list_item.xml as below.

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />
    

    try it out. Hope it will helps you.

    UPDATE :

    You have to manually attach the debugger while the emulator says "Waiting for debugger to attach". In Netbean's menu bar, click "Debug", then "Attach Debugger...". You have to select your package from the "Process" drop down list, and then click "Attach". That should do it.
    This works in Netbeans 7 anyway.
    

    or you can try out below thing also.

    You have two choices: connect a debugger, or kill the process.
    
    Looking at your logcat, you have at least two different desktop applications that are trying to connect to each application process, which is where the "Ignoring second debugger" messages are coming from.
    
    This would happen if you were, say, running Eclipse with the ADT plugin, and the stand-alone DDMS at the same time. I don't know what you're running or what the netbeans plugin does, but I would start by figuring out if you have two different things fighting for control.
    

    EDITED: HOW TO GET TEXT OF AutoCompleteTextView

    just write this code snippet.

    autoCompView.setOnItemClickListener(new OnItemClickListener() {
    
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    // TODO Auto-generated method stub
                    YOURTEXT = autoCompView.getText().toString();
                    //new AsyncGetAutoPlace().execute(autoCompView.getText()
                    //      .toString().trim());
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to Android development. I am following Google's Android classes and
I'm following the android developer tutorials on tab layouts. (im very very new to
I am developing android application for Google TV. I am very new to Google
I am very new to Android development and Java. Have read around but I'm
I'm still very new to Android, but I am trying to keep up by
I am very new with android development. My app has a lot of views/Activity
I am very new to android and I am developing this app which allows
I'm new to Android dev. There's a very pretty state diagram of the MediaPlayer
i m new to this android application development i would be very much grateful
I'm new at Eclipse and the Android applications making so here comes a very

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.