0
The program I am developing compiles, does not show any error, emulo on mobile, however when opening certain screen the application shows error message and closes. In the AS terminal shows the message:
Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'int.com.diego.tecnologiadanet.Domain.Maps.getPhoto()' on a null Object Reference at br.com.diego.tecnologiadanet.Startactivity.onCreate(Startactivity.java:88)
and points to this line:
>>> ivCar.setImageResource(maps.getPhoto()); <<<
tvModel.setText(maps.getModel());
tvBrand.setText(maps.getBrand());
tvDescription.setText( maps.getDescription() );
Here is my function Maps:
public class Maps implements Parcelable {
private String model;
private String brand;
private String description;
private int category;
private String tel;
private int photo;
//public Maps(){}
public Maps(String m, String b, int p){
model = m;
brand = b;
photo = p;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getPhoto() {
return photo;
}
public void setPhoto(int photo) {
this.photo = photo;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public int getCategory() {
return category;
}
public void setCategory(int category) {
this.category = category;
}
// PARCELABLE
public Maps(Parcel parcel){
setModel(parcel.readString());
setBrand(parcel.readString());
setDescription(parcel.readString());
setCategory(parcel.readInt());
setTel(parcel.readString());
setPhoto(parcel.readInt());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString( getModel() );
dest.writeString( getBrand() );
dest.writeString( getDescription() );
dest.writeInt( getCategory() );
dest.writeString( getTel() );
dest.writeInt( getPhoto() );
}
public static final Parcelable.Creator<Maps> CREATOR = new Parcelable.Creator<Maps>(){
@Override
public Maps createFromParcel(Parcel source) {
return new Maps(source);
}
@Override
public Maps[] newArray(int size) {
return new Maps[size];
}
};
}
The error screen function when opening:
public List<Maps> getSetCarList(int qtd, int category){
String[] models = new String[]{"SETOR 1", "SETOR 2", "SETOR 3"};
String[] brands = new String[]{"STATUS - ABASTECENDO", "STATUS - AGUARDANDO", "STATUS - AGUARDANDO"};
int[] categories = new int[]{1, 2, 3};
int[] photos = new int[]{R.drawable.mapa, R.drawable.mapa, R.drawable.mapa};
String[] description = new String[]{"DIAS: 06,07,08 - 13,14,15 - 23,24,25", "DIAS: 06,07,08 - 13,14,15 - 23,24,30", "DIAS: 06,07,08 - 13,14,15 - 23,24,00"};
List<Maps> listAux = new ArrayList<>();
for(int i = 0; i < qtd; i++){
Maps c = new Maps( models[i % models.length], brands[ i % brands.length], photos[i % models.length] );
c.setDescription( description[i % description.length] );
c.setCategory( categories[ i % brands.length ] );
c.setTel("(XX) XXXXXXX");
if(category != 0 && c.getCategory() != category){
continue;
}
listAux.add(c);
}
return(listAux);
}
I hope you help me.