您好,在下面的代码中,我面对列表的空对象引用。在下面的代码中。 访问状态是一个数组,状态下包含对象列表。
我正在尝试访问对象,但是我面临空对象引用
if(isOn) {
Retrofit retrofit = new Retrofit.Builder ( )
.baseUrl (API.URL_BASE)
.addConverterFactory (ScalarsConverterFactory.create ( ))
.addConverterFactory (GsonConverterFactory.create ( )).build ( );
API service = retrofit.create (API.class);
lightID = "1234";
lightType = "1";
level = "4";
List<OnOffStatusList> onOffStatusListList=new ArrayList <> ();
try {
if (OnOFF.isOn ( )) {
Status = "1";
} else {
Status = "0";
}
JSONObject parmobject = new JSONObject ( );
parmobject.put ("Status", Status);
parmobject.put ("lightID", lightID);
parmobject.put ("lightType", lightType);
parmobject.put ("level", level);
// luminary.setImageDrawable(ContextCompat.getDrawable(getContext (), R.drawable.luminaryon));
Call<List<OnOffStatusList>> userCall = service.getMyJSON (parmobject.toString ());
userCall.enqueue(new Callback<List<OnOffStatusList>> () {
@Override
public void onResponse(Call<List<OnOffStatusList>> userCall, Response<List<OnOffStatusList>> response) {
String response1= response.body ().toString ();
Log.d ("response code",response1);
if (response1!=null && response1.equalsIgnoreCase ("200")) {
luminary.setImageDrawable (ContextCompat.getDrawable (getContext ( ), R.drawable.luminaryon));
//onoffStatusList=response