Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.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
HttpClient获取android时发生缓冲区溢出错误_Android_Httpclient - Fatal编程技术网

HttpClient获取android时发生缓冲区溢出错误

HttpClient获取android时发生缓冲区溢出错误,android,httpclient,Android,Httpclient,我正在尝试使用android中的HttpClient从远程站点获取资源。我一直在尝试以下方法 public class Engine { public String test(){ String engineUrl = "http://site/path"; //I used legit site and path here InputStream is = null; String result = ""; try{

我正在尝试使用android中的HttpClient从远程站点获取资源。我一直在尝试以下方法

public class Engine {

    public String test(){
        String engineUrl = "http://site/path"; //I used legit site and path here
        InputStream is = null;
        String result = "";
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet req = new HttpGet(engineUrl);

            HttpResponse response = httpclient.execute(req);  <<----this
            //is = response.getEntity().getContent();

        }catch(Exception e){
            e.printStackTrace();
            Log.e("error", "err");
        }
        return result;
    }
无论如何谢谢你

谢谢大家,我想我解决了这个问题。我必须将AsyncTask用于网络操作,而不是线程类。再次感谢

您不能打电话

v.setText(e.test()) 

因为UI更改必须在UI线程中完成。试一试

final String result = e.test():

runOnUiThread(new Runnable(){
private void run (){
v.setText(result);
}
}).

您尝试下载的资源有多大?对于大型下载,我建议使用DownloadManager:它非常小,大约100-150个ascii字母。好的,BufferOverflowException正好抛出在httpclient.execute(req)的行上?或者别的地方?是的!当我把它评论出来时,它工作得很好。就在httpclient.execute(req)上,我使用了权限INTERNET和访问网络状态。我希望他们能胜任这项工作?
run(). 
final String result = e.test():

runOnUiThread(new Runnable(){
private void run (){
v.setText(result);
}
}).