1

我正在尝试将此代码https://github.com/smanikandan14/Volley-demo/blob/master/volleydemoapp/src/main/java/com/mani/volleydemo/JSONObjectRequestActvity.java改编为我自己的项目。

当我尝试制作 JSONObjectResponse

jsonObjRequest = new JsonObjectRequest(Request.Method.GET, builder.toString(), null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                parseFlickrImageResponse(response);
                mAdapter.notifyDataSetChanged();
            } catch (Exception e) {
                e.printStackTrace();
                showToast("JSON parse error");
            }
            stopProgress();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            // Handle your error types accordingly.For Timeout & No connection error, you can show 'retry' button.
            // For AuthFailure, you can re login with user credentials.
            // For ClientError, 400 & 401, Errors happening on client side when sending api request.
            // In this case you can check how client is forming the api and debug accordingly.
            // For ServerError 5xx, you can do retry or handle accordingly.
            if( error instanceof NetworkError) {
            } else if( error instanceof ClientError) {
            } else if( error instanceof ServerError) {
            } else if( error instanceof AuthFailureError) {
            } else if( error instanceof ParseError) {
            } else if( error instanceof NoConnectionError) {
            } else if( error instanceof TimeoutError) {
            }

            stopProgress();
            showToast(error.getMessage());
        }
    });

但是出现了这个错误:

Cannot resolve symbol 'ClientError'

我尝试过多种方式导入 volley,但似乎都没有。(.jar,编译'com.android.volley:volley:1.0.0',编译'com.mcxiaoke.volley:library:1.0.19'等)。

顺便说一句,我正在使用 Android Studio。

编辑:

我的毕业典礼

apply plugin: 'com.android.application'

android { compileSdkVersion 25 buildToolsVersion "25.0.2"

defaultConfig {
    applicationId "com.tigerspike.interview.oriolgarcia.tigerspickr"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.volley:volley:1.0.0'
}
4

0 回答 0