質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

1573閲覧

Kotlin + Retrofit

退会済みユーザー

退会済みユーザー

総合スコア0

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2017/03/31 04:34

編集2017/03/31 04:37

Retrofitを使って通信処理をしているのですが、booleanの記述方法が分かりません。
JavaをConvert Java File to Kotlin FileでKotlinに変換しエラーなど発生せずに動いているのですがbooleanのデータだけ渡せていない状況です。

Kotlin

1//kotlin 2class Word : Parcelable { 3 @Expose 4 var id: Int? = null 5 @Expose 6 var keyword: String? = null 7 @Expose 8 var type: Int? = null 9 @Expose 10 var level: Int? = null 11 @Expose 12 var summary: String? = null 13 @Expose 14 var description: String? = null 15 @Expose 16 var isAdult: Boolean = false 17 @Expose 18 var isGrotesque: Boolean = false 19 @Expose 20 var isMovie: Boolean = false 21 @Expose 22 var isNonfiction: Boolean = false 23 @Expose 24 var isFiction: Boolean = false 25 @Expose 26 var isAccident: Boolean = false 27 @Expose 28 var isCrime: Boolean = false 29 @Expose 30 var isExecution: Boolean = false 31 @Expose 32 var isHorror: Boolean = false 33 @Expose 34 var isSick: Boolean = false 35 @Expose 36 var isCreature: Boolean = false 37 @Expose 38 var isDrug: Boolean = false 39 @Expose 40 var isWar: Boolean = false 41 @Expose 42 var isNucleus: Boolean = false 43 @Expose 44 var isPsycho: Boolean = false 45 @Expose 46 var isFilth: Boolean = false 47 @Expose 48 var isFunny: Boolean = false 49 @Expose 50 var isViolence: Boolean = false 51 @Expose 52 var isSurprised: Boolean = false 53 @Expose 54 var isWord: Boolean = false 55 @Expose 56 var isMystery: Boolean = false 57 @Expose 58 var isDepression: Boolean = false 59 @Expose 60 var isParaphilia: Boolean = false 61 @Expose 62 var lang: String? = null 63 @Expose 64 var url: String? = null 65 66 override fun describeContents(): Int { 67 return 0 68 } 69 70 override fun writeToParcel(dest: Parcel, flags: Int) { 71 dest.writeValue(this.id) 72 dest.writeString(this.keyword) 73 dest.writeValue(this.type) 74 dest.writeValue(this.level) 75 dest.writeString(this.summary) 76 dest.writeString(this.description) 77 dest.writeByte(if (this.isAdult) 1.toByte() else 0.toByte()) 78 dest.writeByte(if (this.isGrotesque) 1.toByte() else 0.toByte()) 79 dest.writeByte(if (this.isMovie) 1.toByte() else 0.toByte()) 80 dest.writeByte(if (this.isNonfiction) 1.toByte() else 0.toByte()) 81 dest.writeByte(if (this.isFiction) 1.toByte() else 0.toByte()) 82 dest.writeByte(if (this.isAccident) 1.toByte() else 0.toByte()) 83 dest.writeByte(if (this.isCrime) 1.toByte() else 0.toByte()) 84 dest.writeByte(if (this.isExecution) 1.toByte() else 0.toByte()) 85 dest.writeByte(if (this.isHorror) 1.toByte() else 0.toByte()) 86 dest.writeByte(if (this.isSick) 1.toByte() else 0.toByte()) 87 dest.writeByte(if (this.isCreature) 1.toByte() else 0.toByte()) 88 dest.writeByte(if (this.isDrug) 1.toByte() else 0.toByte()) 89 dest.writeByte(if (this.isWar) 1.toByte() else 0.toByte()) 90 dest.writeByte(if (this.isNucleus) 1.toByte() else 0.toByte()) 91 dest.writeByte(if (this.isPsycho) 1.toByte() else 0.toByte()) 92 dest.writeByte(if (this.isFilth) 1.toByte() else 0.toByte()) 93 dest.writeByte(if (this.isFunny) 1.toByte() else 0.toByte()) 94 dest.writeByte(if (this.isViolence) 1.toByte() else 0.toByte()) 95 dest.writeByte(if (this.isSurprised) 1.toByte() else 0.toByte()) 96 dest.writeByte(if (this.isWord) 1.toByte() else 0.toByte()) 97 dest.writeByte(if (this.isMystery) 1.toByte() else 0.toByte()) 98 dest.writeByte(if (this.isDepression) 1.toByte() else 0.toByte()) 99 dest.writeByte(if (this.isParaphilia) 1.toByte() else 0.toByte()) 100 dest.writeString(this.lang) 101 dest.writeString(this.url) 102 } 103 104 constructor() {} 105 106 protected constructor(`in`: Parcel) { 107 this.id = `in`.readValue(Int::class.java.classLoader) as Int 108 this.keyword = `in`.readString() 109 this.type = `in`.readValue(Int::class.java.classLoader) as Int 110 this.level = `in`.readValue(Int::class.java.classLoader) as Int 111 this.summary = `in`.readString() 112 this.description = `in`.readString() 113 this.isAdult = `in`.readByte().toInt() != 0 114 this.isGrotesque = `in`.readByte().toInt() != 0 115 this.isMovie = `in`.readByte().toInt() != 0 116 this.isNonfiction = `in`.readByte().toInt() != 0 117 this.isFiction = `in`.readByte().toInt() != 0 118 this.isAccident = `in`.readByte().toInt() != 0 119 this.isCrime = `in`.readByte().toInt() != 0 120 this.isExecution = `in`.readByte().toInt() != 0 121 this.isHorror = `in`.readByte().toInt() != 0 122 this.isSick = `in`.readByte().toInt() != 0 123 this.isCreature = `in`.readByte().toInt() != 0 124 this.isDrug = `in`.readByte().toInt() != 0 125 this.isWar = `in`.readByte().toInt() != 0 126 this.isNucleus = `in`.readByte().toInt() != 0 127 this.isPsycho = `in`.readByte().toInt() != 0 128 this.isFilth = `in`.readByte().toInt() != 0 129 this.isFunny = `in`.readByte().toInt() != 0 130 this.isViolence = `in`.readByte().toInt() != 0 131 this.isSurprised = `in`.readByte().toInt() != 0 132 this.isWord = `in`.readByte().toInt() != 0 133 this.isMystery = `in`.readByte().toInt() != 0 134 this.isDepression = `in`.readByte().toInt() != 0 135 this.isParaphilia = `in`.readByte().toInt() != 0 136 this.lang = `in`.readString() 137 this.url = `in`.readString() 138 } 139 140 companion object { 141 142 @JvmField 143 val CREATOR: Parcelable.Creator<Word> = object : Parcelable.Creator<Word> { 144 override fun createFromParcel(source: Parcel): Word { 145 return Word(source) 146 } 147 148 override fun newArray(size: Int): Array<Word?> { 149 return arrayOfNulls(size) 150 } 151 } 152 } 153}

Stringやintのデータは渡ってきているのですがbooleanのデータだけ渡ってきていません。
解決策を教えてください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Convert Java File to Kotlin Fileで変換した際にbooleanの変数名の最初にisが追加されていました。
それを変換前の変数名に戻したところ動くようになりました。

Java

1//変換前一部抜粋 2 @Expose 3 private boolean nonfiction; 4 @Expose 5 private boolean fiction;

Convert Java File to Kotlin File変換すると変数名が自動で変更されていました。

kotlin

1//kotlin 2//変換後一部抜粋 3 @Expose 4 var isNonfiction: Boolean = false 5 @Expose 6 var isFiction: Boolean = false

変数名の最初にisが自動で追加されたためJavaコードに記述されている通りに戻しました。

kotlin

1//kotlin 2//変更後 3 @Expose 4 var nonfiction: Boolean = false 5 @Expose 6 var fiction: Boolean = false

これでbooleanの値を受け取れるようになりました。

投稿2017/03/31 05:14

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問