0
Reply

Invalid use of SingleClientConnManager:

JOHN JOHNNNY

JOHN JOHNNNY

9 years ago
804
Hi

I am having challenges with this login form in android using php and mysql each time i try to test in the emulator it shows the progress dialog
with the word validating user and stops instead of it to validate user and move to the next page, it shows the following error
in the stack trace
02-03 18:50:13.094    1900-2081/com.weblinxpro.akinyemi.buttondialog W/SingleClientConnManager? Invalid use of SingleClientConnManager: connection still allocated.
    Make sure to release the connection before allocating another one.
02-03 18:50:16.145    1900-1912/com.weblinxpro.akinyemi.buttondialog I/art? Background sticky concurrent mark sweep GC freed 241(10KB) AllocSpace objects, 0(0B) LOS objects, 754% free, 1767KB/4MB, paused 14.971ms total 246.399ms
02-03 18:50:16.503    1900-2081/com.weblinxpro.akinyemi.buttondialog I/System.out? Exception : Not Found
02-03 18:50:17.228    1900-1912/com.weblinxpro.akinyemi.buttondialog I/art? Background partial concurrent mark sweep GC freed 483(30KB) AllocSpace objects, 0(0B) LOS objects, 754% free, 1743KB/4MB, paused 35.839ms total 786.177ms


see the code below
public class Third extends Activity {

    Button b;
    EditText et,pass;
    TextView tv;
    ProgressDialog dialog = null;
    HttpClient httpclient;
    StringBuffer buffer;
    HttpResponse response;
    HttpPost httppost;
    List<NameValuePair> nameValuePairs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.third);

        b = (Button)findViewById(R.id.Button01);
        et = (EditText)findViewById(R.id.username);
        pass= (EditText)findViewById(R.id.password);
        tv = (TextView)findViewById(R.id.tv);

        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog = ProgressDialog.show(Third.this, "", "Validating User...", true);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        login();
                    }
                }).start();
            }
        });
    }

    void login(){
        try{

            httpclient = new DefaultHttpClient();
            httppost= new HttpPost("http://www.akadakabals.com/public_html/akadalogin/login.php"); // make sure the url is correct.
            //add your data
            nameValuePairs = new ArrayList<NameValuePair>(2);
            // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar,
            nameValuePairs.add(new BasicNameValuePair("username",et.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
            nameValuePairs.add(new BasicNameValuePair("password",pass.getText().toString().trim()));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            //Execute HTTP Post Request
            response=httpclient.execute(httppost);
            // edited by James from coderzheaven.. from here....
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            final String response = httpclient.execute(httppost, responseHandler);
            System.out.println("Response : " + response);
            runOnUiThread(new Runnable() {
                public void run() {
                    tv.setText("Response from PHP : " + response);
                    dialog.dismiss();
                }
            });

            if(response.equalsIgnoreCase("User Found")){
                runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(Third.this, "Login Success", Toast.LENGTH_SHORT).show();
                    }
                });

                startActivity(new Intent(Third.this, UserPage.class));
            }else{
                showAlert();
            }

        }catch(Exception e){
            dialog.dismiss();
            System.out.println("Exception : " + e.getMessage());
        }
    }

    public void showAlert(){
        Third.this.runOnUiThread(new Runnable() {
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(Third.this);
                builder.setTitle("Login Error.");
                builder.setMessage("User not Found.")
                        .setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();
            }
        });
    }
}

Kindly help