gpt4 book ai didi

java - URL 处的 FileNotFoundException

转载 作者:行者123 更新时间:2023-12-02 05:19:04 25 4
gpt4 key购买 nike

我正在尝试从 php url 获取请求。运行时发生文件未找到异常。我在下面的代码中提到了错误行。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;

}

最佳答案

尝试替换此行

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);

关于java - URL 处的 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26649540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com