我想知道爲什麼這個代碼不執行?我試圖通過POST方法從我的設備發送數據,但沒有錯誤。該應用程序剛剛完成自身設備上的通信「我的應用程序已停止:無效使用SingleClientConnManager的:連接仍然分配
下面是執行:
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.
發佈的logcat .. –
_「剛完成的應用程序本身的設備通過comunicate‘我的應用程序是stopped.38’_這意味着你的應用程序崩潰。請給我們日誌。同樣在你的構造函數中,它應該是'this.context = context'。 –
@TGMCians 02-15 17:45:24.695:E/AndroidRuntime(21890):\t在android.widget.Toast。(Toast.java:94) 02-15 17:47:19.343:W/SingleClientConnManager(22288):無效使用SingleClientConnManager的:仍然分配的連接。 02-15 17:47:19.343:W/SingleClientConnManager(22288):請確保在分配另一個連接之前釋放連接。這裏 –
user3310467