OkHttp's NullPointerException in HttpUrl.class

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 = “”;

你可能感兴趣的:(OkHttp's NullPointerException in HttpUrl.class)