覆盖错误消息无法解析主机“<insert url =”“here =”“>”没有与主机名

时间:2018-03-29 13:45:02

标签: java android

我正在使用改造进行邮局服务器调用。我的网络服务器关闭时。我收到了像 Unable to resolve host "<insert URL here>": No address associated with hostname 这样的消息。我想要toast用户可读的错误消息,例如服务器无法访问。我想知道该怎么做。以下是一些相关的代码。

mEasyRetrofit.setPostMethod(WebConstants.CONTACT_FAMILY_LIST_URL, map, hashmap, new WebserviceCallBack() {
    @Override
    public void onResponse(String response, int code) {
        // Some code
    }

    @Override
    public void onFailure(Object response, int code) {
        if (response instanceof String) {
            String str_failure = (String) response;
            CustomToast.animRedTextMethod(getBaseActivity(), "" + str_failure, true);
        }
    }
});

1 个答案:

答案 0 :(得分:1)

您可以尝试使用此代码来解决您的问题:

        @Override
        public void onFailure(Object response, int code) {
            if (response instanceof String) {
              //  String str_failure = (String) response;
                CustomToast.animRedTextMethod(getBaseActivity(), "Server is not reachable" , true);

                // OR simple Add
                Toast.makeText(getActivity(),  "Server is not reachable", Toast.LENGTH_SHORT).show();

            }
        }