저는 Android 프로그래밍에 익숙하지 않고 며칠 동안이 코드를 고수했습니다. "잘못된 SingleClientConnManager 사용 : 연결이 여전히 할당되었습니다."라는 오류가 발생합니다. - 왜 이런 일이 발생하는지 이해하지만 어떻게 해결할 수 있는지 이해하지 못합니다.SingleClientConnManager 및 AsyncTask를 사용하는 중 오류가 발생했습니다.
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)
프로젝트의 뒤에 아이디어는 응용 프로그램에 대한 로그인 기능을 확인하는 것입니다.
나는 해결책을 찾고 웹상에서 도움을 얻으려고 노력하지만, 나는 무엇을 시도하든 이것을 이해할 수 없다. 나는 누군가가 나를 도와 줄 시간을 가지길 바란다. 코드, 오류 등에 대한 자세한 정보가 필요하면 알려주십시오. 추가하겠습니다.
감사합니다. 이전에 나를 도와 주신 모든 분들께 감사드립니다.
나는 그렇게했으나 여전히 같은 오류가 발생합니다. ResponseHandler responseHandler = new BasicResponseHandler(); 최종 문자열 응답 = httpclient.execute (httppost, responseHandler); //Toast.makeText(MainActivity.this,response, Toast.LENGTH_LONG) .show(); if (response.equalsIgnoreCase ("User Found")) { startActivity (새 인 텐트 ("com.example.obligatorisk.BROWSER"))); } httppost.getEntity(). consumeContent(); –
Xantrax