myq_26 2013-06-17 05:26 采纳率: 16.7%
浏览 2638
已采纳

AsyncTask 不能在 4.0.4 上运行

我创建了一个类,这个类连接互联网,然后发送一个请求到php script。我创建的就像 AsyncTask一样,不在主线程中,为了能在4.0.4中执行。但是当我测试时,不能运行。程序可以在2.2上执行。问题出在哪里呢?

class download extends AsyncTask {
    protected String doInBackground(String s1, String s2) {
        String result = "";
        //http post
        ArrayList nameValuePairs = new ArrayList();
        nameValuePairs.add(new BasicNameValuePair("Vreme",s1));
        nameValuePairs.add(new BasicNameValuePair("Datum",s2));
        InputStream is=null;
        try{
                String adresa="http://senzori.open.telekom.rs/script.php";
                HttpPost httppost = new HttpPost(adresa);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
        }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
        }
        //convert response to string
        try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                }
                is.close();
                result=sb.toString();
        }catch(Exception e){
                Log.e("log_tag", "Error converting result "+e.toString());
        }
        return result;
    }
    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        return null;
    }
}
  • 写回答

1条回答 默认 最新

  • 码密码密哄 2013-06-17 05:30
    关注

    doInBackground(String... params) 怎么不是用的这个可变参数的方法,覆写应该是覆写这个方法啊

     @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            return null;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器