Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Java
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
Posted
Updated 3-Feb-15 17:11pm
v2
Comments
Mohibur Rashid 3-Feb-15 23:14pm    
move the following line to onCreate function.
httpclient = new DefaultHttpClient();

then get back to us
Member 10627743 4-Feb-15 16:00pm    
is still the same kindly help
Mohibur Rashid 4-Feb-15 16:42pm    
I think, yesterday I gave you the another suggestion regarding calling network service from another thread. Again, call the network request on AsyncTask

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900