title: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. on api less 24
body: <pre><code>com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
  </code></pre>
  
  <p>I got this error in logcat on api from 19 to 24 and there is no data loading from the server in my app I searched about that error and find that <a href="https://stackoverflow.com/questions/36043324/android-volley-error-trust-anchor-for-certification-path-not-found-only-in-r">solution</a></p>
  
  <pre><code> @SuppressLint("TrulyRandom")
  public static void handleSSLHandshake() {
      try {
          TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
              public X509Certificate[] getAcceptedIssuers() {
                  return new X509Certificate[0];
              }
  
              @Override
              public void checkClientTrusted(X509Certificate[] certs, String authType) {
              }
  
              @Override
              public void checkServerTrusted(X509Certificate[] certs, String authType) {
              }
          }};
  
          SSLContext sc = SSLContext.getInstance("SSL");
          sc.init(null, trustAllCerts, new SecureRandom());
          HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
          HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
              @Override
              public boolean verify(String arg0, SSLSession arg1) {
                  return true;
              }
          });
      } catch (Exception ignored) {
      }
  }
  </code></pre>
  
  <p>and call it in my application class  onCreate and that's solved my problem but in that answer which if find that solution there is a <a href="https://stackoverflow.com/questions/36043324/android-volley-error-trust-anchor-for-certification-path-not-found-only-in-r">hint</a> This code is not relevant and shouldn't be used! it is forbidden by Google.</p>
  
  <p>so anyone knows what's the alternative solution allowed by google for that error? </p>