尊重';response.body()';可能产生';java.lang.NullPointerException

尊重';response.body()';可能产生';java.lang.NullPointerException,java,android,nullpointerexception,textview,Java,Android,Nullpointerexception,Textview,我有个错误。名称是值字符串类型。setText是字符串类型,但我有一个错误 Factory.getInstance().Placeholder Model().enqueue(新回调(){ @凌驾 公共void onResponse(调用、响应){ textView.setText(response.body().name); } 多谢各位 你的建议对我来说很重要这只是一个警告,而不是一个错误,以防止这种使用 if (response.body != null ) {} 或者在方法的标题处

我有个错误。名称是值字符串类型。setText是字符串类型,但我有一个错误

Factory.getInstance().Placeholder Model().enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
textView.setText(response.body().name);
}
多谢各位


你的建议对我来说很重要

这只是一个警告,而不是一个错误,以防止这种使用

if (response.body != null ) {}
或者在方法的标题处使用
注释
@NonNull

表示参数、字段或方法返回值永远不能 不能为空

public void onResponse(@NonNull调用,Response-Response){

您的建议对我很重要您的问题是什么?这不是错误,而是IDE发出的警告,表明响应可能为
null
if (response.body != null ) {}
public void onResponse(@NonNull Call<PlaceHolderModel> call, Response<PlaceHolderModel> response) {