Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从url获取表行文本_Java_Android_Jsoup - Fatal编程技术网

Java 从url获取表行文本

Java 从url获取表行文本,java,android,jsoup,Java,Android,Jsoup,我正在使用Jsoup从表格单元格中提取文本。但是我得到了null错误。我想获取每个的中的文本。我该怎么做 Document doc = Jsoup.connect("URL").get(); //this is where Null error is thrown - but the URL is valid Element table = doc.select("table").first(); Iterator<Element> iterator

我正在使用Jsoup从表格单元格中提取文本。但是我得到了
null
错误。我想获取每个
中的文本。我该怎么做

Document doc = Jsoup.connect("URL").get(); //this is where Null error is thrown - but the URL is valid
     Element table = doc.select("table").first();
            Iterator<Element> iterator = table.select("td").iterator();
            while(iterator.hasNext())
            {
                Log.e("CellText", iterator.next().text());
            }
Document doc=Jsoup.connect(“URL”).get()//这是抛出Null错误的地方-但URL是有效的
元素表=文件选择(“表”).first();
迭代器迭代器=表。选择(“td”).Iterator();
while(iterator.hasNext())
{
Log.e(“CellText”,iterator.next().text());
}
HTML:


Text1

文本2

...
在一个简单的java项目中测试您的代码-->也可以

  • 您的url是否以http://开头
  • 您是否在计算机中运行代码
  • 你的安卓系统会阻止上网吗
  • 请发布stacktrace或有关异常的更多信息

  • 在一个简单的java项目中测试了您的代码-->也可以

  • 您的url是否以http://开头
  • 您是否在计算机中运行代码
  • 你的安卓系统会阻止上网吗
  • 请发布stacktrace或有关异常的更多信息

  • 我把代码放在一个异步任务中,现在它工作了。

    我把代码放在一个异步任务中,现在它工作了。

    从哪里得到空指针?我在标准java项目中尝试过同样的代码,它工作了。有没有可能因为我从onUpdate调用此代码(单独的类)而不起作用?从哪里可以得到空指针?我在标准java项目中尝试了相同的代码,并且成功了。是否可能因为我从onUpdate调用此代码(单独类)而无法工作?如果您的问题已解决,请将此答案标记为。如果您的问题已解决,请将此答案标记为。
     <table border="0" cellspacing="0" cellpadding="0" width="400">
              <tr>
                <td width="100">
                  <p><strong>Text1</strong></p>
                </td>
                <td width="200">
                  <p>Text2</p>
                </td>
              </tr>
             <tr>...