LoginSignup
3
1

More than 3 years have passed since last update.

java弄ってた時に出たエラー

Last updated at Posted at 2020-03-30

Not only pythonエラー備忘録 but also java備忘録

メモ

文字列の設定
String型に値を設定する場合は""、char型に値を設定する場合は''を使おう。

エラー集

java.lang.IllegalStateException: closed

エラーメッセージ

example.java
example E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: example, PID: XXXXX
    java.lang.IllegalStateException: closed
        at okio.RealBufferedSource.select(RealBufferedSource.kt:83)
        at okhttp3.internal.Util.readBomAsCharset(Util.kt:254)
        at okhttp3.ResponseBody.string(ResponseBody.kt:171)
        at example.AsyncHttp$1.onResponse(AsyncHttp.java:107)
        at okhttp3.RealCall$AsyncCall.run(RealCall.kt:138)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

状況&原因
okhttpを使ってサーバ上のテキストを読み取って(GETして)response.body().string()で中身取り出してあれやこれややろうとした。
ココによるとresponse.body().string()は一度しか呼べないとのこと。
今回はログ出力で1回、変数格納で1回の計2回呼び出していた。
オチ
ログ出力の方をコメントアウトしたところ、問題なく動作した。
Responseはとっとと変数に格納するのがよさそうね。

Cannot resolve symbol 'REQUEST_ENABLE_BLUETOOTH'

状況&解決策
AndroidのBluetooth機能のチェック時に発生
参考にしたページ曰く初期化してやればいいとの事

example.java
int REQUEST_ENABLE_BLUETOOTH = 0;//こんな感じに

参考:
https://stackoverflow.com/questions/50948225/cannot-resolve-symbol-request-enable-bluetooth

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1