當前位置: 首頁>>代碼示例>>Java>>正文


Java VolleyError類代碼示例

本文整理匯總了Java中com.android.volley.VolleyError的典型用法代碼示例。如果您正苦於以下問題:Java VolleyError類的具體用法?Java VolleyError怎麽用?Java VolleyError使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VolleyError類屬於com.android.volley包,在下文中一共展示了VolleyError類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getImageListener

import com.android.volley.VolleyError; //導入依賴的package包/類
/**
 * The default implementation of ImageListener which handles basic functionality
 * of showing a default image until the network response is received, at which point
 * it will switch to either the actual image or the error image.
 * @param view The imageView that the listener is associated with.
 * @param defaultImageResId Default image resource ID to use, or 0 if it doesn't exist.
 * @param errorImageResId Error image resource ID to use, or 0 if it doesn't exist.
 */
public static ImageListener getImageListener(final ImageView view,
        final int defaultImageResId, final int errorImageResId) {
    return new ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                view.setImageBitmap(response.getBitmap());
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    };
}
 
開發者ID:wangzhaosheng,項目名稱:publicProject,代碼行數:29,代碼來源:ImageLoader.java

示例2: post

import com.android.volley.VolleyError; //導入依賴的package包/類
/**
 * 發送POST請求, 返回JSONObject對象數據
 * @param url    請求地址
 * @param listener  數據返回回調接口
 * @param params   POST請求參數
 */
public void post(String url, final Fdv_CallBackListener<JSONObject> listener,Map<String,String> params){
    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            if(listener!=null){
                listener.onSuccessResponse(response);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if(listener!=null){
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(jsonObjectRequest,params);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:Fdv_JsonObjectRequest.java

示例3: get

import com.android.volley.VolleyError; //導入依賴的package包/類
/**
 * 普通文本等信息 Get請求 無參數,或者get請求的參數直接拚接在URL上麵
 * @param url  請求的地址
 * @param listener  數據請求返回接口回調
 */
public void get(String url, final Fdv_CallBackListener<String> listener){
    StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            if(listener!=null){
                listener.onSuccessResponse(response);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if(listener!=null){
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(stringRequest);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:Fdv_StringRequest.java

示例4: getImageListener

import com.android.volley.VolleyError; //導入依賴的package包/類
/**
 * The default implementation of ImageListener which handles basic functionality
 * of showing a default image until the network response is received, at which point
 * it will switch to either the actual image or the error image.
 * @param imageView The imageView that the listener is associated with.
 * @param defaultImageResId Default image resource ID to use, or 0 if it doesn't exist.
 * @param errorImageResId Error image resource ID to use, or 0 if it doesn't exist.
 */
public static ImageListener getImageListener(final ImageView view,
        final int defaultImageResId, final int errorImageResId) {
    return new ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                view.setImageBitmap(response.getBitmap());
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    };
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:29,代碼來源:ImageLoader.java

示例5: onErrorResponse

import com.android.volley.VolleyError; //導入依賴的package包/類
@Override
public void onErrorResponse(VolleyError error) {
    Log.e(TAG, "onErrorResponse: " + error.toString());
    findViewById(R.id.articleLoader).setVisibility(View.GONE);

    ConnectivityManager cm = (ConnectivityManager) getBaseContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
            // Display icon
            findViewById(R.id.noNetwork).setVisibility(View.VISIBLE);
            // Display permanent message
            Snackbar.make(findViewById(R.id.coordinatorArticle), getString(R.string.error_no_connection), Snackbar.LENGTH_INDEFINITE)
                    .setAction(getString(R.string.error_no_connection_retry), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            REQUEST_QUEUE.add(new StringRequest(Request.Method.GET, shareLink, articleReceived, errorResponse));
                        }
                    }).show();
        }
    }
}
 
開發者ID:MBach,項目名稱:LeMondeRssReader,代碼行數:23,代碼來源:ArticleActivity.java

示例6: requestJson

import com.android.volley.VolleyError; //導入依賴的package包/類
private void requestJson() {
    RequestManager.addRequest(new StringRequest("http://shop.boohee" +
            ".com/store/pages/story_json", new Listener<String>() {
        public void onResponse(String response) {
            try {
                List<Story> stories = Story.parseStory(response);
                if (stories != null && stories.size() > 0) {
                    WelcomeActivity.this.mDataList.clear();
                    WelcomeActivity.this.mDataList.addAll(stories);
                    WelcomeActivity.this.mAdapter.notifyDataSetChanged();
                    stories.clear();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            WelcomeActivity.this.setRefresh(false);
        }
    }, new ErrorListener() {
        public void onErrorResponse(VolleyError error) {
            Helper.showToast(error.toString());
            WelcomeActivity.this.setRefresh(false);
        }
    }), this);
    setRefresh(true);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:WelcomeActivity.java

示例7: requestPosts

import com.android.volley.VolleyError; //導入依賴的package包/類
public static void requestPosts(final onGetPosts callback){
    RequestQueue queue = Volley.newRequestQueue(App.getAppContext());
    StringRequest stringRequest = new StringRequest(
            Request.Method.GET,
            request.URL.LARAVEL_FEED_URL_LIVE,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    //finally return the posts list
                    VolleyResponseHelper responseHelper = new VolleyResponseHelper(response);
                    callback.onSuccess(responseHelper.getPosts());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(App.Tag,"error : "+VolleyErrorHelper.getMessage(error));
                    callback.onFailure(error);
                }
            }
    );

    queue.add(stringRequest);
}
 
開發者ID:jamesddube,項目名稱:LaravelNewsApp,代碼行數:25,代碼來源:rssRequest.java

示例8: getPosts

import com.android.volley.VolleyError; //導入依賴的package包/類
void getPosts() {
    String url = getArguments().getString(ARG_SECTION_URL);
    url = getString(R.string.tumblr_api_url, url);
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject meta = response.getJSONObject("meta");
                if (meta.getInt("status") == 200) {
                    JSONArray posts = response.getJSONObject("response").getJSONArray("posts");
                    adapter.setPosts(posts);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Activities", error.toString());
        }
    });

    VolleySingleton.getInstance(getContext()).addToRequestQueue(request);
}
 
開發者ID:ypicoleal,項目名稱:FancyTab,代碼行數:26,代碼來源:MainActivity.java

示例9: getPosts

import com.android.volley.VolleyError; //導入依賴的package包/類
@Override
public void getPosts(@NonNull final GetPostsCallback getPostsCallback) {
    GsonRequest<PostList> gsonRequest = new GsonRequest<>(mUrl, PostList.class, null, new Response.Listener<PostList>() {
        @Override
        public void onResponse(PostList list) {
            getPostsCallback.onPostsLoaded(list.posts);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            getPostsCallback.onPostsNotAvailable(volleyError.getMessage(), volleyError.getCause());
            // + "\n" + volleyError.toString()
        }
    });

    mRequestQueue.add(gsonRequest);
}
 
開發者ID:googlecodelabs,項目名稱:android-network-security-config,代碼行數:18,代碼來源:RemoteDataSource.java

示例10: checkErrorType

import com.android.volley.VolleyError; //導入依賴的package包/類
public static String checkErrorType(VolleyError error) {
    String str = "";
    if (error instanceof NoConnectionError) {
        str = ErrorCode.IS_NOT_NETWORK;
    } else if (error instanceof AuthFailureError) {
        str = ErrorCode.AUTH_FAILED;
    } else if (error instanceof TimeoutError) {
        str = ErrorCode.CONNECTION_TIMEOUT;
    } else if (error instanceof ParseError) {
        str = ErrorCode.PARSE_DATA_ERROR;
    } else if (error instanceof ServerError) {
        str = ErrorCode.SERVER_ERROR;
    } else if (error instanceof HttpError) {
        HttpError httpError = (HttpError) error;
        str = httpError.getMessage();
        if (TextUtils.isEmpty(str)) {
            str = ErrorCode.REQUEST_ERROR;
        }
    } else {
        str = ErrorCode.REQUEST_ERROR;
    }
    return str;
}
 
開發者ID:DoloresTeam,項目名稱:dolores-android,代碼行數:24,代碼來源:HttpUtil.java

示例11: requestGetMovies

import com.android.volley.VolleyError; //導入依賴的package包/類
private static void requestGetMovies(String url, final GetMoviesCallback callback,
                                         Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetMovies(MoviesMapping.getMoviesFromResponse(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetMovies();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
 
開發者ID:JonathandelaSen,項目名稱:TheMovies,代碼行數:18,代碼來源:MoviesTask.java

示例12: volleyGetJsonObjectRequest

import com.android.volley.VolleyError; //導入依賴的package包/類
private String volleyGetJsonObjectRequest() {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Constant.JUHE_URL_GET, null, // 用post方式時,需更改為帶請求參數的Object
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();
                }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                }
        });
    request.setTag(JSON_OBJECT_GET_TAG);
    MyApplication.getHttpQueues().add(request);
    return request.getTag().toString();
}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:19,代碼來源:MainActivity.java

示例13: setCountersDK

import com.android.volley.VolleyError; //導入依賴的package包/類
private static void setCountersDK(Context context) {
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, dkCountersURL, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            try {
                dkUsersCount = response.get("users").toString();
                dkProjectsCount = response.get("projects").toString();
                dkTeamsCount = response.get("teams").toString();
                dkLookupsCount = response.get("lookups").toString();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            // log error?
        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(context);
    requestQueue.add(jsonObjectRequest);
}
 
開發者ID:KAEM,項目名稱:android-widget,代碼行數:26,代碼來源:KaemWidget.java

示例14: requestGetCredits

import com.android.volley.VolleyError; //導入依賴的package包/類
private static void requestGetCredits(String url, final GetCastCallback callback,
                                         Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetCast(MoviesMapping.getCast(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetCast();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
 
開發者ID:JonathandelaSen,項目名稱:TheMovies,代碼行數:18,代碼來源:MoviesTask.java

示例15: getActions

import com.android.volley.VolleyError; //導入依賴的package包/類
private void getActions(final DeviceDAO device) {
    Log.d(TAG, "TODO getActions");
    String uri = Uri.parse(String.format("http://%s:%s/", device.getIP(), device.getPort()))
            .buildUpon().build().toString();
    String credentials = device.getUsername() + ":" + device.getPassword();
    byte[] t = credentials.getBytes();
    byte[] auth = Base64.encode(t, Base64.DEFAULT);
    final String basicAuthValue = new String(auth);
    requestQueue.add(new StringRequest(Request.Method.POST, uri, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("Authorization", "Basic " + basicAuthValue);
            params.put("Connection", "close");
            return params;
        }
    });
}
 
開發者ID:MBach,項目名稱:home-automation,代碼行數:28,代碼來源:DeviceActionsResolver.java


注:本文中的com.android.volley.VolleyError類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。