解決android.view.View android.view.ViewStub.inflate()' on a null object reference
異常
解決:就是ViewStub只能調(diào)用inflate一次,代碼如下:
View viewStub = findViewById(R.id.grey_mask_container);
viewStub.inflate();
修改為
View viewStub = findViewById(R.id.grey_mask_container);
if(viewStub != null){
viewStub.inflate();
}
服務(wù)器接收的Json數(shù)據(jù)有問(wèn)題
錯(cuò)誤寫法
try{
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("goodsId", "123456");
jsonArray.put(jsonObject);
JSONObject paramsObj = new JSONObject();
paramsObj.put("goods", jsonArray.toString());
Log.d(TAG, "result: "+paramsObj);
}catch (Exception e){
e.printStackTrace();
}
輸出:
result:{"goods":"[{\"goodsId\":\"123456\"}]"}
正確寫法
try{
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("goodsId", "123456");
jsonArray.put(jsonObject);
JSONObject paramsObj = new JSONObject();
paramsObj.put("goods", jsonArray);
Log.d(TAG, "setupView: "+paramsObj);
}catch (Exception e){
e.printStackTrace();
}
輸出:
result:{"goods":[{"goodsId":"123456"}]}
結(jié)論:JSONArray調(diào)用了toString會(huì)導(dǎo)致服務(wù)器接收的數(shù)據(jù)有""