Jsoup.connect(url)总是抛出异常

时间:2011-03-13 15:40:07

标签: android jsoup

我正在开发一个使用Jsoup来帮助从网络中提取信息的Android应用程序。

我的代码是这样的:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    try {
        String url = "http://www.lcsd.gov.hk/b5/home.php";
        Document doc = Jsoup.connect(url).get();
        String title = doc.title();
        Log.i("ALAN", "Title="+title);

    } catch (Exception e) {
        Log.e("ALAN", "Exception!", e); //since I don't know how to open the display of stack trace in eclipse...
        e.printStackTrace();
    }
}

此外,我确实已在清单中包含互联网权限。而且,我试图将网址更改为“http://www.google.com/”,它运作良好,并告诉我“title = Google”。

例外情况如下:

03-14 11:32:07.151: ERROR/ALAN(29575): Exception!
03-14 11:32:07.151: ERROR/ALAN(29575): java.nio.charset.UnsupportedCharsetException: The supported charset name is "BIG5-HKSCS".
03-14 11:32:07.151: ERROR/ALAN(29575):     at ava.nio.charset.Charset.forName(Charset.java:572)
03-14 11:32:07.151: ERROR/ALAN(29575):     at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:71)
03-14 11:32:07.151: ERROR/ALAN(29575):     at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:408)
03-14 11:32:07.151: ERROR/ALAN(29575):     at org.jsoup.helper.HttpConnection.get(HttpConnection.java:125)
03-14 11:32:07.151: ERROR/ALAN(29575):     at com.webtest.Webtest.onCreate(Webtest.java:29)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.os.Looper.loop(Looper.java:123)
03-14 11:32:07.151: ERROR/ALAN(29575):     at android.app.ActivityThread.main(ActivityThread.java:4363)
03-14 11:32:07.151: ERROR/ALAN(29575):     at java.lang.reflect.Method.invokeNative(Native Method)
03-14 11:32:07.151: ERROR/ALAN(29575):     at java.lang.reflect.Method.invoke(Method.java:521)
03-14 11:32:07.151: ERROR/ALAN(29575):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-14 11:32:07.151: ERROR/ALAN(29575):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-14 11:32:07.151: ERROR/ALAN(29575):     at dalvik.system.NativeStart.main(Native Method)

请帮助,非常感谢!

1 个答案:

答案 0 :(得分:0)

  

03-14 11:32:07.151:ERROR / ALAN(29575):java.nio.charset.UnsupportedCharsetException:不支持的字符集名称为“BIG5-HKSCS”。

这归结为您的Java平台不支持此charset。我不是Android用户,但如果从Android SDK中删除它以节省宝贵的文件/内存空间,我不会感到惊讶。我至少尝试过软件升级或在http://android.stackexchange.com上通知。

请注意,这与Jsoup无关。这只是信使。