使用jsoup.connect

时间:2017-04-13 11:52:35

标签: java android

我在edittext中使用textwatcher来验证字符串是否为url

  if (Patterns.WEB_URL.matcher(url).matches()) {

并将此url传递给asynctask where

  @Override
    protected Void doInBackground(String... params) {
        try {
            while (!isCancelled()) {
                // Connect to the web site
                    document = Jsoup.connect(URLEncoder.encode(URL, "UTF-8"))
                            .userAgent("Mozilla").get();

            }

但是在edittext中键入m.go时,我得到一个malformedURLException:

java.net.MalformedURLException:无协议:M.go

我也试图捕捉异常

 catch (SocketTimeoutException ex) {
            ex.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

你可以帮我解决一个问题,因为应用程序每次都会崩溃

CompleteLog:

E / UncaughtException:java.lang.RuntimeException:执行doInBackground()时发生错误                                                                       在android.os.AsyncTask $ 3.done(AsyncTask.java:325)                                                                       在java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)                                                                       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)                                                                       在java.util.concurrent.FutureTask.run(FutureTask.java:242)                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                                                                       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)                                                                       在java.lang.Thread.run(Thread.java:761)                                                                    引起:java.lang.IllegalArgumentException:格式错误的URL:M.go                                                                       在org.jsoup.helper.HttpConnection.url(HttpConnection.java:101)                                                                       在org.jsoup.helper.HttpConnection.connect(HttpConnection.java:43)                                                                       在org.jsoup.Jsoup.connect(Jsoup.java:73)                                                                       在                                                                       在android.os.AsyncTask $ 2.call(AsyncTask.java:305)                                                                       在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                                                                       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)                                                                       在java.lang.Thread.run(Thread.java:761)                                                                    引起:java.net.MalformedURLException:无协议:M.go                                                                       在java.net.URL。(URL.java:589)                                                                       在java.net.URL。(URL.java:486)                                                                       在java.net.URL。(URL.java:435)                                                                       在org.jsoup.helper.HttpConnection.url(HttpConnection.java:99)                                                                       在org.jsoup.helper.HttpConnection.connect(HttpConnection.java:43)                                                                       在org.jsoup.Jsoup.connect(Jsoup.java:73)                                                                       在                                                                       在                                                                       在android.os.AsyncTask $ 2.call(AsyncTask.java:305)                                                                       在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                                                                       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)                                                                       在java.lang.Thread.run(Thread.java:761)

0 个答案:

没有答案