Ich brauche Hilfe Ich habe versucht, einen Weg zu finden, wie benutzerdefinierte Listenansicht implementieren und ich erhalte eine Fehlermeldung: -Fehler bei Implementierung eigene Listenansicht mit BaseAdapter
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.edis.edis.HospitalAdaptor.getView(HospitalAdaptor.java:62)
Hier finden Sie das Objekt, das Ich habe erstellt und es heißt Data.java
.
public class Data {
private double lat, lon;
public String name;
String groupA, groupB, groupAB,groupO;
public int url_image;
public Data(double lat, double lon, int url_image, String name, String groupA, String groupB, String groupAB, String groupO)
{
this.lat =lat;
this.lon = lon;
this.url_image =url_image;
this.name = name;
this.groupA =groupA;
this.groupB =groupB;
this.groupAB = groupAB;
this.groupO = groupO;
}
}
Dann habe ich einen Adapter erstellt, wo ich einen Fehler (Null-Objekt) erhalten auf der Linie, wo chakula.setText((hospital.name))
ist.
Folgendes ist der Adapter, den ich BaseAdaptor verwendet habe. HospitalsAdaptors.java
public class HospitalAdaptor extends BaseAdapter{
Context context;
List<Data> datas;
public HospitalAdaptor(Context context, List<Data> datas) {
this.context = context;
this.datas = datas;
}
@Override
public int getCount() {
return datas.size();
}
@Override
public Object getItem(int position) {
return datas.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Data hospital = (Data)getItem(position);
if(convertView == null){
convertView = LayoutInflater.from(context).inflate(R.layout.fragment_hospitals,parent,false);
//convertView = LayoutInflater.inflate(R.layout.fragment_hospitals,parent,false);
}
TextView chakula = (TextView)convertView.findViewById(R.id.hospitals_name);
ImageView pilau = (ImageView)convertView.findViewById(R.id.hospitals_image);
chakula.setText(hospital.name);
Glide
.with(context)
.load(hospital.url_image)
.centerCrop()
.crossFade()
.into(pilau);
return convertView;
}
}
Warum verwenden Sie nicht 'ArrayAdapter'? – pskink
Hast du keine Getter und Setter? –
Bitte posten Sie die Layout-Datei auch –