我对android编程很陌生,而且我已经被这段代码困住了好几天了。我得到的错误是“SingleClientConnManager 的使用无效:仍然分配了连接。” - 我理解为什么会发生这种情况,但不知道如何解决它。我正在使用的代码:
protected class loader extends AsyncTask<String, Void, String> {
protected void onPreExecute()
{
nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("username_in",username.getText().toString().trim()));
nameValuePairs.add(new BasicNameValuePair("password_in",password.getText().toString().trim()));
tv.setText("Started onPreExecute");
}
@Override
protected String doInBackground(String... params) {
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://www.myurl.com/phplogin.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
//Toast.makeText(MainActivity.this,response, Toast.LENGTH_LONG).show();
if(response.equalsIgnoreCase("User Found"))
{
httppost.getEntity().consumeContent();
//startActivity(new Intent("com.example.obligatorisk.BROWSER"));
}
}
catch(IOException e){
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result)
{
tv.setText("Reached onPostExecute");
}
// TODO Auto-generated method stub
}
完整的错误日志:
10-18 14:30:52.134: W/SingleClientConnManager(3940): Invalid use of SingleClientConnManager: connection still allocated.
10-18 14:30:52.134: W/SingleClientConnManager(3940): Make sure to release the connection before allocating another one.
10-18 14:30:52.414: W/System.err(3940): org.apache.http.client.HttpResponseException: Internal Server Error
10-18 14:30:52.414: W/System.err(3940): at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71)
10-18 14:30:52.424: W/System.err(3940): at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
10-18 14:30:52.424: W/System.err(3940): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
10-18 14:30:52.424: W/System.err(3940): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
10-18 14:30:52.424: W/System.err(3940): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
10-18 14:30:52.424: W/System.err(3940): at com.example.obligatorisk.MainActivity$loader.doInBackground(MainActivity.java:113)
10-18 14:30:52.424: W/System.err(3940): at com.example.obligatorisk.MainActivity$loader.doInBackground(MainActivity.java:1)
10-18 14:30:52.424: W/System.err(3940): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-18 14:30:52.434: W/System.err(3940): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-18 14:30:52.434: W/System.err(3940): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-18 14:30:52.434: W/System.err(3940): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-18 14:30:52.443: W/System.err(3940): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-18 14:30:52.443: W/System.err(3940): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-18 14:30:52.443: W/System.err(3940): at java.lang.Thread.run(Thread.java:856)
该项目背后的想法是为应用程序制作登录功能。
我一直试图在网上寻找解决方案和帮助,但无论我尝试什么,我都无法弄清楚。我真的希望有人会花时间在这里帮助我。如果您需要有关代码、错误等的更多信息,请告诉我,我会添加。
谢谢你,也感谢之前帮助过我的每一个人。