URL中的java.io.FileNotFoundException

时间:2017-12-20 15:57:58

标签: java android

我正在创建一个应用程序,以便在网站上发布新闻时发送通知(https://www.noticiasaominuto.com/tech),但是当我去运行时会发生以下错误:

  

java.io.FileNotFoundException:https://www.noticiasaominuto.com/tech

完整堆栈跟踪:

  

12-20 16:36:41.135 6835-7089 / test.m4ur0.inovar W / System.err:java.io.FileNotFoundException:https://www.noticiasaominuto.com/tech   12-20 16:36:41.135 6835-7089 / test.m4ur0.inovar W / System.err:at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238)   12-20 16:36:41.135 6835-7089 / test.m4ur0.inovar W / System.err:at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)   12-20 16:36:41.135 6835-7089 / test.m4ur0.inovar W / System.err:at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)   12-20 16:36:41.135 6835-7089 / test.m4ur0.inovar W / System.err:at test.m4ur0.inovar.GetNota.doInBackground(GetNota.java:41)   12-20 16:36:41.135 6835-7089 / test.m4ur0.inovar W / System.err:at test.m4ur0.inovar.GetNota.doInBackground(GetNota.java:13)   12-20 16:36:41.136 6835-7089 / test.m4ur0.inovar W / System.err:at android.os.AsyncTask $ 2.call(AsyncTask.java:295)   12-20 16:36:41.136 6835-7089 / test.m4ur0.inovar W / System.err:at java.util.concurrent.FutureTask.run(FutureTask.java:237)   12-20 16:36:41.136 6835-7089 / test.m4ur0.inovar W / System.err:at android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:234)   12-20 16:36:41.136 6835-7089 / test.m4ur0.inovar W / System.err:at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)   12-20 16:36:41.136 6835-7089 / test.m4ur0.inovar W / System.err:at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:588)   12-20 16:36:41.136 6835-7089 / test.m4ur0.inovar W / System.err:at java.lang.Thread.run(Thread.java:818)

如果有人可以帮助我,这就是代码:

    @Override
    protected String doInBackground(String... params) {
    String nota = "";

    String sURL = "https://www.noticiasaominuto.com/tech";
    try{
        URL url = new URL(sURL);
        HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
        httpCon.addRequestProperty("Host", "https://www.noticiasaominuto.com/tech");
        httpCon.addRequestProperty("Connection", "keep-alive");
        httpCon.addRequestProperty("Cache-Control", "max-age=0");
        httpCon.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        httpCon.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36");
        httpCon.addRequestProperty("Referer", "google.com");
        HttpURLConnection.setFollowRedirects(false);
        httpCon.setInstanceFollowRedirects(false);
        httpCon.setDoOutput(true);
        httpCon.setUseCaches(true);
        httpCon.setRequestMethod("GET");

        BufferedReader in = new BufferedReader(new InputStreamReader(httpCon.getInputStream(), "UTF-8"));
        String inputLine;
        StringBuilder a = new StringBuilder();
        while ((inputLine = in.readLine()) != null)
            a.append(inputLine);
        in.close();

        String codeN = a.toString().split("<div class=\"col-lg-4 col-md-6 col-sm-6 col-xs-12 article-thumb-block tech \">")[1];
        codeN = codeN.toString().split("</div>")[0];

        nota = codeN.split("alt=")[1].split("class=")[0].replace("\"", "");

        httpCon.disconnect();

        try{
            Thread.sleep(1000*30);
        }catch(InterruptedException e){
            System.out.println("\n \n ERRO TIMER \n \n" + e + "\n \n \n \n");
        }


    }catch (MalformedURLException e){
        System.out.println("\n \n ERRO 1 \n \n" + e + "\n \n \n \n");
        return nota+"1";
    }catch (IOException e){
        System.out.println("\n \n ERRO 2 \n \n" + e + "\n \n \n \n");
        return nota+"2";
    }

    return nota;
}

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
}

这是AsyncTask

0 个答案:

没有答案