Java.Lang.Nullpointerexception: Attempt to Invoke Virtual Method 'Int Android.View.View.Getimportantforaccessibility()' on a Null Object Reference

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference

In your public View getView method change return null; to return convertView;.

Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference

Hello Naresh Negi You have to just remove a single line from earthquakeAdapter

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater earthquake = LayoutInflater.from(getContext());
// View customView = convertView;
if(convertView == null){
convertView = earthquake.inflate(R.layout.custom_layout,parent,false);

}
earthquake currentEarthquakeAdapter = getItem(position);
TextView Magnitude = (TextView) convertView.findViewById(R.id.magnitude);
Magnitude.setText(currentEarthquakeAdapter.get_magnitude());
TextView Location = (TextView) convertView.findViewById(R.id.location);
Location.setText(currentEarthquakeAdapter.get_location());

return convertView;
}

Use convertView instead of assigning every time. We have just assign only first time after that it will hold the reference of the view in adapter



Related Topics



Leave a reply



Submit