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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:15:33+00:00 2026-05-23T03:15:33+00:00

In the following list.java i am making a URL near the bottom that grabs

  • 0

In the following list.java i am making a URL near the bottom that grabs the current location and adds it to the URL. I have a PHP script taking the location from the URL and then doing its thing and returning a Array based off JSON. I need to get the URL string to be accessed in the HttpPost located in the oncreate area of my Code.

public class List extends ListActivity {

    int ct_id;
    String[] ct_number = null;
    String[] ct_address = null;
    String[] ct_phone = null;
    String[] ct_fax = null;
    String[] ct_email = null;
    String[] ct_city = null;
    String[] ct_province = null;
    String[] ct_country = null;
    String[] ct_pcode = null;
    String[] ct_lat = null;
    String[] ct_long = null;
    String[] ct_distance = null;
    String[] ct_show = null;
    String[] ct_listinfo = null;

    MyLocation myLocation = new MyLocation();

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.timslist);
        findCurrentLocation();

        String result = null;
        InputStream is = null;
        StringBuilder sb = null;
        //http post
        try{

            HttpClient httpclient = new DefaultHttpClient();

                    //This is where i need the myurl string to be accessed
            HttpPost httppost = new HttpPost(Need_the_myurl_String_here);

            //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());
        }
        //convert response to string
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");
            String line="0";
            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());
        }
        //paring data
        JSONArray jArray;
        try{
            jArray = new JSONArray(result);
            JSONObject json_data=null;
            ct_number=new String[jArray.length()];
            ct_address=new String[jArray.length()];
            ct_phone=new String[jArray.length()];
            ct_fax=new String[jArray.length()];
            ct_email=new String[jArray.length()];
            ct_city=new String[jArray.length()];
            ct_province=new String[jArray.length()];
            ct_country=new String[jArray.length()];
            ct_pcode=new String[jArray.length()];
            ct_lat=new String[jArray.length()];
            ct_long=new String[jArray.length()];
            ct_distance=new String[jArray.length()];
            ct_listinfo=new String[jArray.length()];
            for(int i=0;i<jArray.length();i++){
                json_data = jArray.getJSONObject(i);
                ct_id=json_data.getInt("location_id");
                ct_number[i]=json_data.getString("store_number");
                ct_address[i]=json_data.getString("store_address");
                ct_phone[i]=json_data.getString("store_phone");
                ct_fax[i]=json_data.getString("store_fax");
                ct_email[i]=json_data.getString("store_email");
                ct_city[i]=json_data.getString("store_city");
                ct_province[i]=json_data.getString("store_province");
                ct_country[i]=json_data.getString("store_country");
                ct_pcode[i]=json_data.getString("store_pcode");
                ct_lat[i]=json_data.getString("store_lat");
                ct_long[i]=json_data.getString("store_long");
                ct_distance[i]=json_data.getString("store_distance");
                ct_listinfo[i] = new String (ct_address[i] + "\n" + ct_city[i] + ", " + ct_province[i] + " - " + ct_distance[i] + " Km Away");
            }
        }
        catch(JSONException e1){
            Toast.makeText(getBaseContext(), "No Locations Found" ,Toast.LENGTH_LONG).show();
        } catch (ParseException e1) {
            e1.printStackTrace();
        }

        setListAdapter(new ArrayAdapter<String>(this,R.layout.listview,ct_listinfo));
        ListView lv;
        lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setCacheColorHint(Color.TRANSPARENT);
        lv.setBackgroundColor(Color.TRANSPARENT);
        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> timslist, View view,
                    int position, long id) {

                Intent i = new Intent(getApplicationContext(), ListMore.class);

                i.putExtra("ct_number_pass", ct_number[position]);
                i.putExtra("ct_address_pass", ct_address[position]);
                i.putExtra("ct_phone_pass", ct_phone[position]);
                i.putExtra("ct_city_pass", ct_city[position]);
                i.putExtra("ct_province_pass", ct_province[position]);
                i.putExtra("ct_country_pass", ct_country[position]);
                i.putExtra("ct_pcode_pass", ct_pcode[position]);
                i.putExtra("ct_distance_pass", ct_distance[position]);

                startActivity(i);

            }
        });
    }

    private void findCurrentLocation() {
        myLocation.getLocation(this, locationResult);
    }

    public LocationResult locationResult = new LocationResult() {

        @Override
        public void gotLocation(Location location) {
            // TODO Auto-generated method stub
            if (location != null) {

                    //Here is the String i am trying to access
                String myurl  = "http://www.doamin.com/list.php?lat=" + location.getLatitude() + "&long=" + location.getLongitude();

            }
        }
    };
}

I have tried with the help of others but cant seem to get this working right so i am trying to see if there is a easy and workable solution out there.

  • 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-05-23T03:15:34+00:00Added an answer on May 23, 2026 at 3:15 am

    You can’t do this: you are trying to access the location value BEFORE it is returned to you. You should:

    1. Add a Handler instance to your class.
    2. Move the HttpClient/HttpPost calls into a separate method.
    3. Send a Message to the Handler from the gotLocation method with the location data.
    4. Call that method from the Handler with the location data from step 3 above.

    EDIT: try creating a method like this:

    void updateData(String url)
    {
            String result = null;
            InputStream is = null;
            StringBuilder sb = null;
            //http post
            try{
    
                HttpClient httpclient = new DefaultHttpClient();
    
                        //This is where i need the myurl string to be accessed
                HttpPost httppost = new HttpPost(url);
    
                //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());
            }
            //convert response to string
            try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                sb = new StringBuilder();
                sb.append(reader.readLine() + "\n");
                String line="0";
                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());
            }
            //paring data
            JSONArray jArray;
            try{
                jArray = new JSONArray(result);
                JSONObject json_data=null;
                ct_number=new String[jArray.length()];
                ct_address=new String[jArray.length()];
                ct_phone=new String[jArray.length()];
                ct_fax=new String[jArray.length()];
                ct_email=new String[jArray.length()];
                ct_city=new String[jArray.length()];
                ct_province=new String[jArray.length()];
                ct_country=new String[jArray.length()];
                ct_pcode=new String[jArray.length()];
                ct_lat=new String[jArray.length()];
                ct_long=new String[jArray.length()];
                ct_distance=new String[jArray.length()];
                ct_listinfo=new String[jArray.length()];
                for(int i=0;i<jArray.length();i++){
                    json_data = jArray.getJSONObject(i);
                    ct_id=json_data.getInt("location_id");
                    ct_number[i]=json_data.getString("store_number");
                    ct_address[i]=json_data.getString("store_address");
                    ct_phone[i]=json_data.getString("store_phone");
                    ct_fax[i]=json_data.getString("store_fax");
                    ct_email[i]=json_data.getString("store_email");
                    ct_city[i]=json_data.getString("store_city");
                    ct_province[i]=json_data.getString("store_province");
                    ct_country[i]=json_data.getString("store_country");
                    ct_pcode[i]=json_data.getString("store_pcode");
                    ct_lat[i]=json_data.getString("store_lat");
                    ct_long[i]=json_data.getString("store_long");
                    ct_distance[i]=json_data.getString("store_distance");
                    ct_listinfo[i] = new String (ct_address[i] + "\n" + ct_city[i] + ", " + ct_province[i] + " - " + ct_distance[i] + " Km Away");
                }
            }
            catch(JSONException e1){
                Toast.makeText(getBaseContext(), "No Locations Found" ,Toast.LENGTH_LONG).show();
            } catch (ParseException e1) {
                e1.printStackTrace();
            }
    
            setListAdapter(new ArrayAdapter<String>(this,R.layout.listview,ct_listinfo));
            ListView lv;
            lv = getListView();
            lv.setTextFilterEnabled(true);
            lv.setCacheColorHint(Color.TRANSPARENT);
            lv.setBackgroundColor(Color.TRANSPARENT);
            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> timslist, View view,
                        int position, long id) {
    
                    Intent i = new Intent(getApplicationContext(), ListMore.class);
    
                    i.putExtra("ct_number_pass", ct_number[position]);
                    i.putExtra("ct_address_pass", ct_address[position]);
                    i.putExtra("ct_phone_pass", ct_phone[position]);
                    i.putExtra("ct_city_pass", ct_city[position]);
                    i.putExtra("ct_province_pass", ct_province[position]);
                    i.putExtra("ct_country_pass", ct_country[position]);
                    i.putExtra("ct_pcode_pass", ct_pcode[position]);
                    i.putExtra("ct_distance_pass", ct_distance[position]);
    
                    startActivity(i);
    
                }
            });
    
    }
    
    void updateList(final String url)
    {
       getListView().post(new Runnable(){ public void run(){ updateData(url); }});
    }
    

    and then do this in gotLocation:

    @Override
            public void gotLocation(Location location) {
                // TODO Auto-generated method stub
                if (location != null) {
    
                        //Here is the String i am trying to access
                        updateList("http://www.doamin.com/list.php?lat=" + location.getLatitude() + "&long=" + location.getLongitude());
                }
            }
    

    You’ll need to fix up any compile errors, but something like this should work for you.

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

Sidebar

Related Questions

Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private
The following shell script takes a list of arguments, turns Unix paths into WINE/Windows
I have Java classes with the following structure (the class names do not imply
I have an ArrayList that im populating within java and passing it off to
Hi I have 2 classes in Java, Gossip and Node , I want that
Given the following: List<List<Option>> optionLists; what would be a quick way to determine the
Assume you are doing something like the following List<string> myitems = new List<string> {
How do I retrieve an item at random from the following list? foo =
Take the following snippet: List<int> distances = new List<int>(); Was the redundancy intended by
I am using the ListView Control with the following datasource List<MyObject> On my listview

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.