I'm working on an app in Android Studio and want to transfer data from my City instance to next activity by intent. To do that, I generated the Parcelable code with Plugin "Android Parcelable code generator".
Now I'm getting the following error message during compile time:
Error:(19, 1) error: constructor City in class City cannot be applied to given types;
required: Parcel
found: boolean,String,int[],LatLng
reason: actual and formal argument lists differ in length
City class:
import android.os.Parcel;
import android.os.Parcelable;
import com.google.android.gms.maps.model.LatLng;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Setter
@Getter
@EqualsAndHashCode
@Builder(builderMethodName = "hiddenBuilder")
@ToString
public class City implements Parcelable {
private boolean isSolved;
private final String name;
private int[] imageIds;
private LatLng latLng;
public static CityBuilder builder(String name) {
return hiddenBuilder().name(name);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeByte(this.isSolved ? (byte) 1 : (byte) 0);
dest.writeString(this.name);
dest.writeIntArray(this.imageIds);
dest.writeParcelable(this.latLng, flags);
}
protected City(Parcel in) {
this.isSolved = in.readByte() != 0;
this.name = in.readString();
this.imageIds = in.createIntArray();
this.latLng = in.readParcelable(LatLng.class.getClassLoader());
}
public static final Parcelable.Creator<City> CREATOR = new Parcelable.Creator<City>() {
@Override
public City createFromParcel(Parcel source) {
return new City(source);
}
@Override
public City[] newArray(int size) {
return new City[size];
}
};
}
What needs to be done to make Lombok's Builder Annotation work with Parcel?
Add parameterized constructor with boolean,String,int[],LatLng in your POJO, You can refer following code:
public City(boolean isSolved, String name,int[] imageIds,LatLng latLng) {
this.isSolved = isSolved;
this.name = name;
this.imageIds = imageIds;
this.latLng = latLng;
}