java.lang.NullPointerException: Attempt to get length of null array
See original GitHub issueThis code produces NPE:
static {
// Init okhttp.
OkHttpClient.Builder builder = new OkHttpClient.Builder();
TrustManager[] trustAllCerts = { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
// Not implemented
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
// Not implemented
}
}};
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
builder.sslSocketFactory(sc.getSocketFactory());
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
HTTP_CLIENT = builder.build();
}
Stacktrace:
java.lang.ExceptionInInitializerError
at ru.xseconds.xseconds.app.activity.WelcomeActivity.onResume(WelcomeActivity.java:46)
...
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at okhttp3.internal.tls.CertificateAuthorityCouncil.<init>(CertificateAuthorityCouncil.java:44)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:190)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:60)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:719)
at ru.xseconds.xseconds.net.API.<clinit>(API.java:88)
....
There was no error in 3.0.1
version, started to crash in 3.1+
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
android - Attempt to get length of null array (readDirectory())
But why do I have a readDirectory fail when the path is good? package com.example.androidexplorer; import java.io.File; import java.util.
Read more >java.lang.NullPointerException: Attempt to get length of null ...
NullPointerException : Attempt to get length of null array at java.util.Formatter$FormatSpecifier.addZeros(Formatter.java:3505) at java.util.
Read more >Attempt to get length of null array at org.mozilla.gecko ...
Startup Crash in java.lang.NullPointerException: Attempt to get length of null array at org.mozilla.gecko.GeckoApp$DeferredCleanupTask.run(GeckoApp.java).
Read more >Internal NullPointerException: Attempt to read from null array ...
Fatal Exception: java.lang.NullPointerException: Attempt to read from null array at java.util.ArrayList.get(ArrayList.java:310)
Read more >I am getting error "Attempt to get length of null array" - Treehouse
Probably there is a problem with parceling(marshalling and unmarshallng) the data. So I think the 'parcebles' array that you declared is empty ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey, I had also this error. I managed to fixed it by changing ‘return null;’ for ‘return new X509Certificate[0];’ in getAcceptedIssuers()
I had the same problem. I think this is not an OkHttp issue. When you read the javadoc for
getAcceptedIssuers
the method must return a non null value.