使用无效的SingleClientConnManager:连接仍然分配 [英] Invalid use of SingleClientConnManager: connection still allocated

查看:211
本文介绍了使用无效的SingleClientConnManager:连接仍然分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我wanto知道为什么不执行此code?我试图通过POST方法从设备发送我的数据,但没有任何错误。刚刚完成的应用程序本身对comunicate我的应用程序的设备被停止。

下面是执行

  KlientNameValue KN =新KlientNameValue(getApplicationContext());
kn.new MyAsyncTask()执行(zam.klient.getNazwa(),zam.klient.getNip(),zam.klient.getAdres());

和这里是code:

 公共类KlientNameValue {清单<&的NameValuePair GT; KlientNameValuePairs =新的ArrayList<&的NameValuePair GT;();
上下文语境;
公共KlientNameValue(上下文的背景下){
    超();
    this.context =背景;
} 公共类MyAsyncTask扩展的AsyncTask<弦乐,太虚,太虚> {      @覆盖保护无效doInBackground(字符串... PARAMS){
          // TODO自动生成方法存根
          POSTDATA(PARAMS [0],则params [1],则params [2]);
      返回null;      }      @覆盖
      保护无效onPostExecute(虚空结果){      Toast.makeText(上下文中,Zleceniezostałowysłane,
     Toast.LENGTH_LONG).show();
          }      无效POSTDATA(由...字符串,字符串夹,字符串ADRES){
          HttpClient的HttpClient的=新DefaultHttpClient();
          HttpPost httppost =新HttpPost(这里是我的默认链接:));      尝试{//添加数据      KlientNameValuePairs =新的ArrayList<&的NameValuePair GT;();
      KlientNameValuePairs.add(新BasicNameValuePair(Kli_imie由...));
      KlientNameValuePairs.add(新BasicNameValuePair(Kli_adresADRES));
      KlientNameValuePairs.add(新BasicNameValuePair(Kli_nr_telefonu
      掐));      httppost.setEntity(新UrlEn codedFormEntity(KlientNameValuePairs));
      HTT presponse响应= httpclient.execute(httppost);
      //httppost.setEntity(new UrlEn codedFormEntity(
      // ZamowienieNameValuePairs)); // Htt的presponse response1 =      }赶上(IOException异常五){// TODO自动生成catch块
      e.printStackTrace(); }      }      }

}

错误:

  02-15 17:45:24.695:E / AndroidRuntime(21890):在android.widget.Toast<&初始化GT;(Toast.java:94)
02-15 17:47:19.343:W / SingleClientConnManager(22288):使用无效的SingleClientConnManager:连接仍然分配。
 02-15 17:47:19.343:W / SingleClientConnManager(22288):确保释放分配另一个之前的连接。


解决方案

  

无效使用SingleClientConnManager的:连接仍然分配


您正在执行的HTTP请求两次你使用它之前是完全错误的。因此,删除第二个 httpclient.execute(httppost); ,因为你已经执行该http请求

和调用这个

  HTT presponse.getEntity()consumeContent()。


  

以上方法被调用以指示此实体的内容不再需要。所有实体实现预计释放所有分配的资源,该方法调用的结果


I wanto know why does this code not executing? I'm trying to send my data from device by POST method but there is no error. Just app finish itself on device by comunicate "My app was stopped.:

Here is execution

KlientNameValue kn = new KlientNameValue(getApplicationContext());
kn.new  MyAsyncTask().execute(zam.klient.getNazwa(),zam.klient.getNip(),zam.klient.getAdres());

And here is code:

public class KlientNameValue {

List<NameValuePair> KlientNameValuePairs = new ArrayList<NameValuePair>();
Context context;
public KlientNameValue(Context context) {
    super();
    this.context=context;
}



 public class MyAsyncTask extends AsyncTask<String, Void, Void> {

      @Override protected Void doInBackground(String... params) { 
          // TODO     Auto-generated method stub 
          postData(params[0], params[1], params[2]);
      return null;

      }

      @Override
      protected void onPostExecute(Void result) {

      Toast.makeText(context , "Zlecenie zostało wysłane",
     Toast.LENGTH_LONG).show();
          }

      void postData(String nazwa, String nip, String adres) {
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("here is my default link :)");

      try { // Add your data

      KlientNameValuePairs = new ArrayList<NameValuePair>();
      KlientNameValuePairs.add(new BasicNameValuePair("Kli_imie", nazwa));
      KlientNameValuePairs.add(new BasicNameValuePair("Kli_adres", adres));
      KlientNameValuePairs.add(new BasicNameValuePair( "Kli_nr_telefonu",
      nip)); 



      httppost.setEntity(new UrlEncodedFormEntity( KlientNameValuePairs));
      HttpResponse response = httpclient.execute(httppost);
      //httppost.setEntity(new UrlEncodedFormEntity( 
      //      ZamowienieNameValuePairs)); // HttpResponse response1 =



      } catch (IOException e) { // TODO Auto-generated catch block
      e.printStackTrace(); }

      }

      }

}

Error:

02-15 17:45:24.695: E/AndroidRuntime(21890): at android.widget.Toast.<init>(Toast.java:94) 
02-15 17:47:19.343: W/SingleClientConnManager(22288): Invalid use of SingleClientConnManager: connection still allocated.
 02-15 17:47:19.343: W/SingleClientConnManager(22288): Make sure to release the connection before allocating another one. 

解决方案

Invalid use of SingleClientConnManager: connection still allocated.

You are executing the http request two times that is completely wrong before you consume it. So remove the second httpclient.execute(httppost); because you have already execute this http request.

and call this

httpResponse.getEntity().consumeContent();

Above method is called to indicate that the content of this entity is no longer required. All entity implementations are expected to release all allocated resources as a result of this method invocation

这篇关于使用无效的SingleClientConnManager:连接仍然分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆