OkHttp's NullPointerException in HttpUrl.class

简介: 1 java.lang.RuntimeException:Unable to resume activity {com.xxxx.center/com.xxxx.
1 java.lang.RuntimeException:Unable to resume activity {com.xxxx.center/com.xxxx.center.activity.LoadActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
2 android.app.ActivityThread.performResumeActivity(ActivityThread.java:3284)
3 ......
4 java.lang.NullPointerException:Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
5 okhttp3.HttpUrl.canonicalize(HttpUrl.java:1612)
6 okhttp3.FormBody$Builder.add(FormBody.java:110)
7 com.xxx.http.okhttp.request.PostFormRequest.addParams(PostFormRequest.java:125)
8 com.xxx.http.okhttp.request.PostFormRequest.buildRequestBody(PostFormRequest.java:40)
9 com.xxx.http.okhttp.request.OkHttpRequest.generateRequest(OkHttpRequest.java:70)
10 com.xxx.http.okhttp.request.RequestCall.generateRequest(RequestCall.java:79)
11 com.xxx.http.okhttp.request.RequestCall.buildCall(RequestCall.java:55)
12 com.xxx.http.okhttp.request.RequestCall.execute(RequestCall.java:84)
13 com.xxx.center.utils.HttpUtils.post(HttpUtils.java:45)
14 com.xxx.center.manager.AppBuessinesManager.serverInit(AppBuessinesManager.java:74)
15 com.xxx.center.activity.LoadActivity.onResume(LoadActivity.java:302)
16 android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1267)
17 android.app.Activity.performResume(Activity.java:6567)
18 android.app.ActivityThread.performResumeActivity(ActivityThread.java:3269)
19 android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3315)
20 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2651)
21 android.app.ActivityThread.access$800(ActivityThread.java:182)
22 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
23 android.os.Handler.dispatchMessage(Handler.java:111)
24 android.os.Looper.loop(Looper.java:194)
25 android.app.ActivityThread.main(ActivityThread.java:5766)
26 java.lang.reflect.Method.invoke(Native Method)
27 java.lang.reflect.Method.invoke(Method.java:372)
28 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1059)
29 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:825)

今天测试在小米5.0-6.0的机型中测试发现一个空指针的异常,经过排查后发现OkHttp的请求参数不能为null,这个请求接口会上传当前机型的手机号、ip地址和其他的一些物理参数,当没有获取成功时就返回null,所以对于参数进行判空,否则就赋值为 parameter = “”;

相关文章
Mockito框架抛出NullPointerException
一文详细讲解Mockito框架是怎么抛出NullPointerException的整个过程和解决方式。
6073 0
|
7月前
|
搜索推荐 Java 开发者
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException 问题处理
【5月更文挑战第14天】org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException 问题处理
799 1
|
2月前
|
Java 容器
Java“NullPointerException”解决
Java中的“NullPointerException”是当程序试图使用一个空对象引用时抛出的异常。解决方法包括:检查变量是否为null、使用Optional类、利用断言和合理初始化变量等。确保代码健壯性,避免运行时错误。
41 0
|
Java Maven
【异常】java: Internal error in the mapping processor: java.lang.NullPointerException
【异常】java: Internal error in the mapping processor: java.lang.NullPointerException
341 0
|
7月前
|
Java Spring
java.lang.Exception: Method a() should be public
java.lang.Exception: Method a() should be public
77 0
|
Java
如何优雅的避免Java中:NullPointerException(空指针异常)
如何优雅的避免Java中:NullPointerException(空指针异常)
119 0
|
Java 开发者
Java:Optional处理NullPointerException空指针异常的利器
Java:Optional处理NullPointerException空指针异常的利器
164 0
|
Java 数据库 Spring
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
|
SQL Java 关系型数据库
记录:springboot使用resultType空指针java.lang.NullPointerException: null...【亲测有效】
记录:springboot使用resultType空指针java.lang.NullPointerException: null...【亲测有效】
438 0
PowerMock - java.lang.RuntimeException: test should never throw an exception to this level
PowerMock - java.lang.RuntimeException: test should never throw an exception to this level
775 0
PowerMock - java.lang.RuntimeException: test should never throw an exception to this level