Husein Behboudi Rad
Husein Behboudi Rad

Reputation: 5462

Keep getting Java.IO.FileNotFoundException exception at monodroid application

I'm using below codes for downloading data from Google and getting a location keyword lat lng in my monodroid application:

public  LatLng  GetLatLng (String input)
    {
        HttpURLConnection conn = null;
        StringBuilder jsonResults = new StringBuilder ();
        LatLng gp = null;
        string str = null;
        try {
            StringBuilder sb = new StringBuilder (GEOCODER_API_BASE + OUT_JSON);
            sb.Append ("?address=" + input + "&sensor=true");
            /// "http://maps.googleapis.com/maps/api/geocode/json?address=Paris&sensor=true"
            URL url = new URL (sb.ToString ());
            conn = (HttpURLConnection)url.OpenConnection ();
            Java.IO.InputStreamReader inp = new Java.IO.InputStreamReader (conn.InputStream);

            // Load the results into a StringBuilder
            int read;
            char[] buff = new char[1024];
            while ((read = inp.Read (buff)) != -1) {
                jsonResults.Append (buff, 0, read);
            }
            str = jsonResults .ToString();



        } catch (System.IO.IOException e) {
            RltLog .HandleException (e, "\nError connecting to Places API\n");
            return gp;
        } finally {
            if (conn != null) {
                conn.Disconnect ();
            }
        }
        try {
            // Create a JSON object hierarchy from the results

            JObject address = JObject .Parse (str);            
            JArray ja = (JArray)address ["results"];

            JObject LocationJObejct = (JObject)ja [0] ["geometry"] ["location"];
            gp = HelperMethods .executeLocationPoint (LocationJObejct ["lat"].ToString (),
                                               LocationJObejct ["lng"].ToString ());


        } catch (Exception e) {
            RltLog .HandleException (e);
        }
        return gp;
    }

But I keep getting these error:

 Exception of type 'Java.IO.FileNotFoundException' was thrown. 

I'm wondering what is the reason?

Upvotes: 1

Views: 702

Answers (1)

Husein Behboudi Rad
Husein Behboudi Rad

Reputation: 5462

You should replace spaces with + in your request based on the google docs.

Upvotes: 2

Related Questions