我正在開發Android Studio中的應用程序,並且希望將數據從我的城市實例傳輸到下一個活動。爲此,我使用Plugin「Android Parcelable code generator」生成了Parcelable代碼。構造函數不能應用於給定的類型;要求:包裹;實際和正式參數列表的長度不同
現在我在編譯時得到以下錯誤信息:
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
城市類:
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];
}
};
}
需要採取哪些措施,使龍目島與包裹builder註釋工作?
可以嘗試在POJO中添加布爾型,String,int [],LatLng參數化構造函數? – Reena
添加建設者類請 –
@Oussema Aroua:建設者類是由lombok生成的。 –