我试图从php url.File获取请求在运行时没有发现异常。我在下面的代码中提到了错误行.Stacktrace似乎没有得到来自url的响应。
堆栈跟踪:
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;
}
答案 0 :(得分:2)
尝试替换此行
String temp=sName.replace(" ","%20");
URL js = new URL("http://192.11.my api.php"+temp);
带
String temp=URLEncoder.encode("http://192.11.my api.php/"+sName, "UTF-8");
URL js = new URL(temp);