Java recvfrom失败:当没有Internet访问时,EconReset(由对等方重置连接)

Java recvfrom失败:当没有Internet访问时,EconReset(由对等方重置连接),java,android,Java,Android,我正在为android开发一个应用程序,从冰淇淋三明治到果冻豆android版本 我有一个功能,检测是否有互联网连接,这是伟大的作品 但是,当设备已连接但无法访问Internet时,它会崩溃并向我发送以下消息 HttpRequest$HttpRequestException: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer) 例如,当divice有3G数据,但没有互联网接入,因为它没

我正在为android开发一个应用程序,从冰淇淋三明治到果冻豆android版本

我有一个功能,检测是否有互联网连接,这是伟大的作品

但是,当设备已连接但无法访问Internet时,它会崩溃并向我发送以下消息

HttpRequest$HttpRequestException: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
例如,当divice有3G数据,但没有互联网接入,因为它没有任何数据平衡

我正在使用向服务器发出请求

我还尝试捕获异常以处理错误并提供用户反馈,但Eclipse向我发送了一个错误

this exception is never thrown for the try statement body
这是我第一次尝试

    if(LaConstante.isConected(ctx)){
        try{
            new ObtenerTiposReporte().execute(b.getString("tipo"));
        }catch(IOException e){
            if (e.getMessage().indexOf("Connection reset by peer") > 0);
        }
    }else{
        ProgressBar progressBarListaReportes = (ProgressBar) findViewById(R.id.progressBarListaReportes);
        progressBarListaReportes.setVisibility(View.INVISIBLE);
        Toast.makeText(ctx, "Lo sentimos, se requiere de una conexión a Internet para reportar", Toast.LENGTH_LONG).show();
        Intent i2 = new Intent(ctx, MainActivity.class);
        startActivity(i2);
    }
我还尝试在发出请求时直接捕获异常

        String jsonString = "";

        try{
            jsonString = HttpRequest.post(LaConstante.getInstance().TIPOS_DE_REPORTE+params[0]).form(data).body();
        }catch(IOException e){
            if (e.getMessage().indexOf("Connection reset by peer") > 0);
        }

我不知道如何处理该错误,以便向用户反馈发生了什么。

您在日志中的一行使它看起来好像是在HttpRequest类中捕获并解释此异常,而不是由它抛出回调用堆栈。如果是这样,那么Eclipse确实是正确的,您需要找到其他方法来确定是否发生了这种情况。