顯示具有 [Android Studio] 標籤的文章。 顯示所有文章
顯示具有 [Android Studio] 標籤的文章。 顯示所有文章

2017年12月5日 星期二

Okhttp3 onResonse報java.lang.IllegalStateException: closed Error

今天在試OKhttp3時,

發現


 OkHttpClient okHttpClient = new OkHttpClient();


        Request request = new Request.Builder()
                .url(DATA_URL)
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d(TAG, "onFailure: " + e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.d(TAG, "onResponse: " + response.body().string());
                String result = response.body().string();
                parseJson(result);
            }
        });


這樣寫居然會報

java.lang.IllegalStateException: closed

                                                                                 


此exception,

後來發現

原來

 response.body().string()

被調用一次就會被close了,

只要將 Log.d註解起來,直接存入String再使用即可通過編譯

2015年6月2日 星期二

Android Studio 使用Git設定

Android Studio 使用Git設定

1. 先到Android Studio VCS→ Import into Version Control → Create Git Repository

2. 在GitLab或GitHub上建立專案。

3. 將Git上面的指令選擇Https, Git init那幾行指令 貼到你的terminal

4. 專按右鍵Git→Add 後 就可以進行commit 、push