gpt4 book ai didi

java - 无效使用 SingleClientConnManager : connection still allocated

转载 作者:搜寻专家 更新时间:2023-11-01 08:52:32 26 4
gpt4 key购买 nike

我想知道为什么这段代码不执行?我正在尝试通过 POST 方法从我的设备发送数据,但没有错误。该应用程序通过传达“我的应用程序已停止。”在我的设备上自行完成:

这里是执行:

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

这里是代码:

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(); }

}

}

错误:

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.

你在消费它之前执行了两次完全错误的http请求。所以删除第二个 httpclient.execute(httppost); 因为你已经执行了这个 http 请求。

然后调用它

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

关于java - 无效使用 SingleClientConnManager : connection still allocated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21800495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com