android studioで開発中のアプリをConvert Java File to Kotlin Fileで変換したところうまく動かなくなりました。
エラーが発生しているのはRetrofitで使うデータクラスの部分です。
Parcelableはプラグインを使って作成しました。
Java
1public class Comment implements Parcelable { 2 @Expose 3 private int id; 4 @Expose 5 private String userName; 6 @Expose 7 private String comment; 8 @Expose 9 private String datetime; 10 11 @Override 12 public String toString() { 13 return "Comment{" + 14 "id=" + id + 15 ", userName='" + userName + '\'' + 16 ", comment='" + comment + '\'' + 17 ", datetime='" + datetime + '\'' + 18 '}'; 19 } 20 21 public int getId() { 22 return id; 23 } 24 25 public void setId(int id) { 26 this.id = id; 27 } 28 29 public String getUserName() { 30 return userName; 31 } 32 33 public void setUserName(String userName) { 34 this.userName = userName; 35 } 36 37 public String getComment() { 38 return comment; 39 } 40 41 public void setComment(String comment) { 42 this.comment = comment; 43 } 44 45 public String getDatetime() { 46 return datetime; 47 } 48 49 public void setDatetime(String datetime) { 50 this.datetime = datetime; 51 } 52 53 @Override 54 public int describeContents() { 55 return 0; 56 } 57 58 @Override 59 public void writeToParcel(Parcel dest, int flags) { 60 dest.writeInt(this.id); 61 dest.writeString(this.userName); 62 dest.writeString(this.comment); 63 dest.writeString(this.datetime); 64 } 65 66 public Comment() { 67 } 68 69 protected Comment(Parcel in) { 70 this.id = in.readInt(); 71 this.userName = in.readString(); 72 this.comment = in.readString(); 73 this.datetime = in.readString(); 74 } 75 76 public static final Creator<Comment> CREATOR = new Creator<Comment>() { 77 @Override 78 public Comment createFromParcel(Parcel source) { 79 return new Comment(source); 80 } 81 82 @Override 83 public Comment[] newArray(int size) { 84 return new Comment[size]; 85 } 86 }; 87}
これをConvert Java File to Kotlin Fileで変換すると赤波線が出ます。
上記のコードをKotlinで記述するにはどうすればいいのか教えてください。
変換後のコードは下記。
Kotlin
1//Kotlin 2class Comment : Parcelable { 3 @Expose 4 var id: Int = 0 5 @Expose 6 var userName: String? = null 7 @Expose 8 var comment: String? = null 9 @Expose 10 var datetime: String? = null 11 12 override fun toString(): String { 13 return "Comment{" + 14 "id=" + id + 15 ", userName='" + userName + '\'' + 16 ", comment='" + comment + '\'' + 17 ", datetime='" + datetime + '\'' + 18 '}' 19 } 20 21 override fun describeContents(): Int { 22 return 0 23 } 24 25 override fun writeToParcel(dest: Parcel, flags: Int) { 26 dest.writeInt(this.id) 27 dest.writeString(this.userName) 28 dest.writeString(this.comment) 29 dest.writeString(this.datetime) 30 } 31 32 constructor() {} 33 34 protected constructor(`in`: Parcel) { 35 this.id = `in`.readInt() 36 this.userName = `in`.readString() 37 this.comment = `in`.readString() 38 this.datetime = `in`.readString() 39 } 40 41 companion object { 42 43 val CREATOR: Parcelable.Creator<Comment> = object : Parcelable.Creator<Comment> { 44 override fun createFromParcel(source: Parcel): Comment { 45 return Comment(source) 46 } 47 48 override fun newArray(size: Int): Array<Comment> {//<Comment?>にすると波線は消えますがうまく動きません 49 return arrayOfNulls(size) 50 } 51 } 52 } 53}
エラーメッセージ
Caused by: android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called CREATOR on class com.example.myapplication.Commnet
意味が分からなかったらすみません。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/03/31 00:39