feat:fix ListAdapter npe

This commit is contained in:
pengfei.zhou 2019-12-10 13:40:20 +08:00
parent 3127b6fcd7
commit 5ca914fda3

View File

@ -60,7 +60,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
@Override @Override
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) { public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
JSValue jsValue = getItemModel(position); JSValue jsValue = getItemModel(position);
if (jsValue.isObject()) { if (jsValue != null && jsValue.isObject()) {
JSObject jsObject = jsValue.asObject(); JSObject jsObject = jsValue.asObject();
holder.listItemNode.setId(jsObject.getProperty("id").asString().value()); holder.listItemNode.setId(jsObject.getProperty("id").asString().value());
holder.listItemNode.blend(jsObject.getProperty("props").asObject()); holder.listItemNode.blend(jsObject.getProperty("props").asObject());
@ -75,7 +75,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
JSValue value = getItemModel(position); JSValue value = getItemModel(position);
if (value.isObject()) { if (value != null && value.isObject()) {
if (value.asObject().getProperty("identifier").isString()) { if (value.asObject().getProperty("identifier").isString()) {
return value.asObject().getProperty("identifier").asString().value().hashCode(); return value.asObject().getProperty("identifier").asString().value().hashCode();
} }