ListView Adapter Class:
public class ListViewAdapter extends ArrayAdapter {
private Context context;
private int resource;
private ArrayList<HashMap<String,String>> list2 = new ArrayList<>();
public ListViewAdapter(Context context,int resource, List<HashMap<String, String>> list) {
super(context, resource, list);
this.resource = resource;
this.context = context;
this.list2 = (ArrayList<HashMap<String, String>>) list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
ViewHolder holder;
Object newMap = list2.get(position);
if (row == null){
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(resource, parent, false);
holder = new ViewHolder();
holder.name1 = (TextView) row.findViewById(R.id.name);
holder.add = (TextView) row.findViewById(R.id.address);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
String pname = ((HashMap<String, String>) newMap).get("place_name");
holder.name1.setText(pname);
return row;
}
public class ViewHolder {
TextView name1,add;
}
}
All data coming in ListView
Adapter class. But when we try to show data into list view it's got a crash.
The Crash shown here holder.name1.setText(pname)
in ListView Adapter
class. And error show NullPointerException