JSoup.connect(String url).get上的java.lang.ExceptionInInitializerError

时间:2012-12-11 00:32:02

标签: android jsoup air-native-extension

我在Android AIR Native Extension中遇到了一个奇怪的问题。

我正在尝试从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;
    }
}

这是adb catlog

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

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

是的@ user1814155是对的,我花了2天时间:D

Make sure the Jsoup library is in the Libs folder. I spend a good 2 hours banging my head against this error when that was the problem. Hope this helps, cheers. – user1814155