Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Android中使用RestClientException捕获_Java_Spring_Rest - Fatal编程技术网

Java 如何在Android中使用RestClientException捕获

Java 如何在Android中使用RestClientException捕获,java,spring,rest,Java,Spring,Rest,我有一个Rest Web服务,我正在使用下面的android代码中的Web服务 web服务运行良好,我已经测试过了 但在下面的代码中,我得到了一个错误 String url ="http://10.0.2.2:29512/Restweb_2/webresources/generic/shirish"; RestTemplate resttemplate = new RestTemplate(); Log.v("in1", "in1"); resttemplate.getMes

我有一个Rest Web服务,我正在使用下面的android代码中的Web服务

web服务运行良好,我已经测试过了

但在下面的代码中,我得到了一个错误

  String url ="http://10.0.2.2:29512/Restweb_2/webresources/generic/shirish";

  RestTemplate resttemplate = new RestTemplate();
    Log.v("in1", "in1");
 resttemplate.getMessageConverters().add(new StringHttpMessageConverter());
    Log.v("in2", "in2");
   String result;
        try {            
            result = resttemplate.getForObject(url,String.class);
        } 
        catch (RestClientException ex) {
           ![I am getting this error while using this exception and I am not able to proceed further if I don't use this exception(Or it is giving me error in result assign statment)][1]. So how to use RestClient!Exception ????? Also I already import the needed jar files.

        }
所需的不兼容类型throwable发现RestClientException


当您包含spring-android-rest-template-xxxx.jar而没有包含spring-android core xxxx.jar时,可能会出现这种情况

您需要帮助来删除或处理
RestClientException
?但是如果我删除了异常,那么行“result=restemplate.getForObject(url,String.class);”是给我的错误必须由try-catch块舍入,普通的try-catch也给出相同的错误。所以这一定是RestClientException的问题。我不理解你的问题<每当遇到客户端HTTP错误时,
RestTemplate
就会抛出code>RestClientException。现在你的期望是什么?首先对不起。我只想在Catch子句中使用RestClientException,但在编写Catch(RestClientException ex)时,它给了我一个错误错误:-找到RestClientException所需的不兼容类型throwable。所以我想在catch子句中使用restclientexception。是否清楚,或者我是否需要详细说明?检查类
RestClientException
是否在您拥有的jar版本中实现了
Throwable
。spring-android-core jar可以从这里下载-