Отображение исключения нулевого указателя ** в этом коде.
** yrWebService.getUserInfo () **
Я пробовал большинство вещей, но не могу понять это.Кто-нибудь, пожалуйста, помогите исправить эту проблему.GetUserInfo () выбрасывает исключение нулевого указателя.кто-нибудь, помогите мне решить это.Я вставил интерфейс туда.
public void fetchUserProfile() {
YRWebService.getUserInfo()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<YRUserResponse>() {
@Override
public void onError(Throwable e) {
Toast.makeText(YarraApplication.this, "Error on server :" +e, Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete() {
}
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(YRUserResponse yrUserResponse) {
//progressDialog.dismiss();
if (yrUserResponse != null) {
if (yrUserResponse.getUser() != null) {
YRPreferenceManager.setString(PreferenceKeys.USER_PROFILE_RESPONSE,
new Gson().toJson(yrUserResponse));
YRUser yrUser = yrUserResponse.getUser();
YarraApplication.userId = yrUserResponse.getUser().getUser_id();
YarraApplication.access = yrUserResponse.getUser().getGoogle_access_token();
YarraApplication.email = yrUser.getEmail();
YarraApplication.fName = yrUser.getFirst_name();
YarraApplication.lName = yrUser.getLast_name();
YarraApplication.mobile = yrUser.getTelephone();
}else {
// YRUtils.showUnknownErrorDialog(YarraApplication.this);
}
}// else {
// YRUtils.showUnknownErrorDialog(UserProfileActivity.this);
// }
}
});
}
**Interface :::: **
Интерфейс, который мы используем здесь, это
public interface YRWebService {
@GET("/users")
Observable<YRUserResponse> getUserInfo();
}
public class YRUserResponse {
List<YRError> errors;
YRUser user;
public YRUser getUser() {
return user;
}
public void setUser(YRUser user) {
this.user = user;
}
**retrofit.RetrofitError**:
```
2019-05-06 15:26:49.506 30475-30475/com.rever.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rever.app, PID: 30475
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rever.app/com.rever.app.UserProfileActivity}: retrofit.RetrofitError
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6635)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: retrofit.RetrofitError
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy0.getUserInfo(Unknown Source)
at com.rever.app.UserProfileActivity.fetchUserProfile(UserProfileActivity.java:220)
at com.rever.app.UserProfileActivity.onCreate(UserProfileActivity.java:132)
at android.app.Activity.performCreate(Activity.java:7084)
at android.app.Activity.performCreate(Activity.java:7075)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6635)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1450)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:102)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:90)
at java.net.InetAddress.getAllByName(InetAddress.java:787)
at com.squareup.okhttp.internal.Dns$1.getAllByName(Dns.java:29)
at com.squareup.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:231)
at com.squareup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:317)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
at com.squareup.okhttp.Call.getResponse(Call.java:198)
at com.squareup.okhttp.Call.execute(Call.java:80)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy0.getUserInfo(Unknown Source)
at com.rever.app.UserProfileActivity.fetchUserProfile(UserProfileActivity.java:220)
at com.rever.app.UserProfileActivity.onCreate(UserProfileActivity.java:132)
at android.app.Activity.performCreate(Activity.java:7084)
at android.app.Activity.performCreate(Activity.java:7075)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6635)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
```