我一直在开发一个应用程序,可以解析三个网站页面上的信息,然后向用户显示解析后的信息。自从这开始运作以来,过去的几周我从未有过任何例外。然后今天,当我再次测试解析功能时,我没有得到任何结果,logcat给出了SSLHandshakeException以及一系列系统错误。以下错误来自logcat:

03-05 17:59:39.834: W/System.err(5525): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.834: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
03-05 17:59:39.834: W/System.err(5525):     at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
03-05 17:59:39.834: W/System.err(5525):     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)
03-05 17:59:39.834: W/System.err(5525):     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:446)
03-05 17:59:39.839: W/System.err(5525):     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
03-05 17:59:39.839: W/System.err(5525):     at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
03-05 17:59:39.839: W/System.err(5525):     at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
03-05 17:59:39.839: W/System.err(5525):     at com.example.queryApp.QueryActivity.onCreate(QueryActivity.java:50)
03-05 17:59:39.839: W/System.err(5525):     at android.app.Activity.performCreate(Activity.java:5206)
03-05 17:59:39.839: W/System.err(5525):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-05 17:59:39.839: W/System.err(5525):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-05 17:59:39.839: W/System.err(5525):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-05 17:59:39.844: W/System.err(5525):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-05 17:59:39.844: W/System.err(5525):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-05 17:59:39.844: W/System.err(5525):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 17:59:39.844: W/System.err(5525):     at android.os.Looper.loop(Looper.java:137)
03-05 17:59:39.844: W/System.err(5525):     at android.app.ActivityThread.main(ActivityThread.java:4898)
03-05 17:59:39.844: W/System.err(5525):     at java.lang.reflect.Method.invokeNative(Native Method)
03-05 17:59:39.844: W/System.err(5525):     at java.lang.reflect.Method.invoke(Method.java:511)
03-05 17:59:39.844: W/System.err(5525):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-05 17:59:39.849: W/System.err(5525):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-05 17:59:39.849: W/System.err(5525):     at dalvik.system.NativeStart.main(Native Method)
03-05 17:59:39.849: W/System.err(5525): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.849: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:192)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:163)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:573)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
03-05 17:59:39.854: W/System.err(5525):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
03-05 17:59:39.854: W/System.err(5525):     ... 27 more
03-05 17:59:39.854: W/System.err(5525): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.859: W/System.err(5525):     ... 32 more


以下是负责解析网页的QueryActivity的部分代码。我将另一个活动的三个网站的URL传递到QueryActivity中,然后使用Jsoup进行连接并获取html进行解析。

public class QueryActivity extends Activity
{
   String fWebsite = getIntent().getStringExtra("fURL");
   String sWebsite = getIntent().getStringExtra("sURL");
   String tWebsite = getIntent().getStringExtra("tURL");
   try{
       Document doc1 = Jsoup.connect(fWebsite).timeout(0).get();
       Document doc2 = Jsoup.connect(sWebsite).timeout(0).get();
       Document doc3 = Jsoup.connect(tWebsite).timeout(0).get();
      }
  catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    }
}


有人可以解释为什么会发生这种情况以及对该问题的任何解决方案,据我所知,我没有在此活动中更改任何代码(QueryActivity)?
谢谢。

最佳答案

如果此问题在您身边:
 1.检查设备的日期/时间。
 2.也许您更改了固件版本或安装了一些更新。

09-28 12:54