我在 Android AIR 本机扩展中遇到了一个奇怪的 JSoup 问题。
我正在尝试从 YouTube 加载页面以从评论中提取一些数据。
这是“违规”代码:
private class ConnectToYouTube {
public String html = null;
public Exception error = null;
}
private class ConnectToYouTubeTask extends AsyncTask<String, Void, ConnectToYouTubeResult>
{
@Override
protected ConnectToYouTubeResult doInBackground(String... params)
{
ConnectToYouTubeResult result = new ConnectToYouTubeResult();
String videoId = params[0];
try {
Document doc = Jsoup.connect("http://www.youtube.com/watch?v="+videoId).get(); // in the catlog this is line 138
Elements foo = doc.select("#comment-text");
result.html = foo.html();
} catch (IOException e) {
result.error = e;
}
return result;
}
}
这是亚行目录
E/AndroidRuntime(12131): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(12131): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(12131): at android.os.AsyncTask$3.done(AsyncTask.java:299)
E/AndroidRuntime(12131): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
E/AndroidRuntime(12131): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
E/AndroidRuntime(12131): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
E/AndroidRuntime(12131): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
E/AndroidRuntime(12131): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
E/AndroidRuntime(12131): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
E/AndroidRuntime(12131): at java.lang.Thread.run(Thread.java:856)
E/AndroidRuntime(12131): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime(12131): at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:210)
E/AndroidRuntime(12131): at org.jsoup.nodes.Document.<init>(Document.java:18)
E/AndroidRuntime(12131): at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:27)
E/AndroidRuntime(12131): at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:40)
E/AndroidRuntime(12131): at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:37)
E/AndroidRuntime(12131): at org.jsoup.parser.Parser.parseInput(Parser.java:30)
E/AndroidRuntime(12131): at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:102)
E/AndroidRuntime(12131): at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:481)
E/AndroidRuntime(12131): at org.jsoup.helper.HttpConnection.get(HttpConnection.java:149)
E/AndroidRuntime(12131): at com.freshplanet.ane.AirYouTube.extractor.YouTubeExtractor$ConnectToYouTubeTask.doInBackground(YouTubeExtractor.java:138)
E/AndroidRuntime(12131): at com.freshplanet.ane.AirYouTube.extractor.YouTubeExtractor$ConnectToYouTubeTask.doInBackground(YouTubeExtractor.java:1)
E/AndroidRuntime(12131): at android.os.AsyncTask$2.call(AsyncTask.java:287)
E/AndroidRuntime(12131): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
E/AndroidRuntime(12131): ... 4 more
E/AndroidRuntime(12131): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime(12131): at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Entities.java:20)
E/AndroidRuntime(12131): ... 17 more
E/AndroidRuntime(12131): Caused by: java.lang.NullPointerException: in == null
E/AndroidRuntime(12131): at java.util.Properties.load(Properties.java:246)
E/AndroidRuntime(12131): at org.jsoup.nodes.Entities.loadEntities(Entities.java:137)
E/AndroidRuntime(12131): at org.jsoup.nodes.Entities.<clinit>(Entities.java:121)
E/AndroidRuntime(12131): ... 18 more
任何帮助将不胜感激。谢谢!