我正在尝试使用Jsoup库从URL解析HTML
但是当我进行调试时,我发现此异常抛出
> 12-09 08:48:09.741 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem
W/System.err: java.lang.IllegalArgumentException: Header name must not be empty
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.Validate.notEmpty(Validate.java:102)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.HttpConnection$Base.header(HttpConnection.java:300)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.HttpConnection$Response.processResponseHeaders(HttpConnection.java:850)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.HttpConnection$Response.setupFromConnection(HttpConnection.java:785)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:577)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:548)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:235)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at org.jsoup.helper.HttpConnection.get(HttpConnection.java:224)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at com.example.virusmahmoudaidi.parkbookingsystem.Activities.FindEmptyPark$GetData.doInBackground(FindEmptyPark.java:474)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at com.example.virusmahmoudaidi.parkbookingsystem.Activities.FindEmptyPark$GetData.doInBackground(FindEmptyPark.java:459)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-09 08:48:09.751 5188-5422/com.example.virusmahmoudaidi.parkbookingsystem W/System.err: at java.lang.Thread.run(Thread.java:856)
当编译器到达Jsoup HTML调用行时抛出此异常:-
Document doc = Jsoup.connect(urls[0]).timeout(0).get();
我的HTML页面:-
<html>
<head>
<META charset='UTF-8' HTTP-EQUIV='refresh' CONTENT='5'/>
<title>Arduino Web Server</title>
</head>
<body style="background-color:#FF0000">
<h1>25</h1>
<br>
<h1>40</h1>
<br>
<h1>30</h1>
<br>
<h1>15</h1>
<br>
</body>
</html>
请提示...
答案 0 :(得分:1)
此问题是由名称为“空”或空值引起的
最近,我刚刚开始我的jsoup开发并发现了这个问题。
在地图标题中
尝试先删除空名称标头:
headers.remove(“”); headers.remove(null);