登录服务中的未知DU异常

时间:2016-01-15 14:06:56

标签: java android codacy

Codacy表示我有一个DU异常("最近定义的变量未定义。这些异常可能出现在正常的源文本中。")变量stringRequest。 我无法找到它,任何人都可以帮助我吗?感谢。

public static void login(@NonNull final LoginListener callback,
                         @NonNull final Context context,
                         @NonNull final JsonObject loginParams) {
    final RestApi restApi = RestApi.getInstance(context);
    final String loginURL = String.format("%s%s", RestApi.URL, "/api/login");
    final StringRequest stringRequest = new StringRequest(POST, loginURL,
            new Listener<String>() {
                /**
                 * {@inheritDoc}
                 */
                @Override
                public void onResponse(final String response) {
                    Log.i(TAG, response);
                    if (response.contains("Error")) {
                        if (response.contains("A non-existent user can not login")) {
                            callback.onLoginPetitionFailure
                                    (context.getString
                                            (R.string.login_non_existing_user_error_message));
                        }
                        if (response.contains("A Cancelled user can not login")) {
                            callback.onLoginPetitionFailure
                                    (context.getString
                                            (R.string.login_canceled_user_error_message));
                        }
                    } else {
                        final Gson gson = new Gson();
                        final UserResponse userResponse = gson.fromJson(response,
                                UserResponse.class);
                        callback.onLoginPetitionSuccess(userResponse.toUser());
                    }
                }
            }, new ErrorListener() {
        /**
         * {@inheritDoc}
         */
        @Override
        public void onErrorResponse(final VolleyError error) {
            Log.i(TAG, "Error while contacting to the server");
            callback.onLoginPetitionFailure(context.getString
                    (R.string.login_server_contacting_error_message));
        }
    }) {
        /**
         * {@inheritDoc}
         */
        @Override
        public byte[] getBody() throws AuthFailureError {
            final String stringParams = loginParams.toString();
            return stringParams.getBytes();
        }
    };
    restApi.addToRequestQueue(stringRequest);
}

0 个答案:

没有答案