Reputation: 10059
I am trying to get the request from the php url.File not found exception occurred at runtime.I mentioned the error line in the below code.Stacktrace seems to be doesn't get the response from the url.
StackTrace:
10-30 05:57:23.000: D/URL(2735): Connectionhttp://example.php
10-30 05:13:37.600: W/System.err(2577): java.io.FileNotFoundException: http://myapi.phpBa
10-30 05:13:37.600: W/System.err(2577): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
10-30 05:13:37.600: W/System.err(2577): at com.manishkpr.autotextviewexample.JsonParse.getParseJsonWCF(JsonParse.java:32)
10-30 05:13:37.610: W/System.err(2577): at com.manishkpr.autotextviewexample.SuggestionAdapter$1.performFiltering(SuggestionAdapter.java:39)
10-30 05:13:37.610: W/System.err(2577): at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
10-30 05:13:37.610: W/System.err(2577): at android.os.Handler.dispatchMessage(Handler.java:102)
10-30 05:13:37.610: W/System.err(2577): at android.os.Looper.loop(Looper.java:136)
10-30 05:13:37.610: W/System.err(2577): at android.os.HandlerThread.run(HandlerThread.java:61)
JSONParse.java:
public List<SuggestGetSet> getParseJsonWCF(String sName)
{
List<SuggestGetSet> ListData = new ArrayList<SuggestGetSet>();
try {
String temp=sName.replace(" ","%20");
URL js = new URL("example.php"+temp);
Log.d("URL","Connection"+js);
URLConnection urlConnection = js.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); ---32 nd line
String line = reader.readLine();
JSONObject jsonResponse = new JSONObject(line);
JSONArray jsonArray = jsonResponse.getJSONArray("search");
for(int i = 0; i < jsonArray.length(); i++){
JSONObject r = jsonArray.getJSONObject(i);
ListData.add(new SuggestGetSet(r.getString("id"),
r.getString("name")));
}
} catch (Exception e1) {
e1.printStackTrace();
}
return ListData;
}
Upvotes: 0
Views: 6403
Reputation: 3195
try replace this lines
String temp=sName.replace(" ","%20");
URL js = new URL("http://192.11.my api.php"+temp);
with
String temp=URLEncoder.encode("http://192.11.my api.php/"+sName, "UTF-8");
URL js = new URL(temp);
Upvotes: 2