URL的FileNotFoundException [英] FileNotFoundException at URL

查看:161
本文介绍了URL的FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从php url获取请求.在运行时发生文件未找到异常.我在下面的代码中提到了错误行.Stacktrace似乎没有从url获得响应.

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;

        }

推荐答案

尝试替换此行

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

这篇关于URL的FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆