• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Wamp Login Database

hi friends
i doing the project to check the username and password is correct or not, which is connect with database (wamp server), but i have error at the time of running the project. logcat also enclosed with this.

Code:
package Com.User;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class UserName extends Activity {
    String user,pass;
    
    /** Called when the activity is first created. */

    EditText euser, epass;
    Button login;
    TextView txt;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button login = (Button) findViewById(R.id.login);
        EditText euser = (EditText) findViewById(R.id.eusername);
        EditText epass = (EditText) findViewById(R.id.epassword);
        TextView txt = (TextView) findViewById(R.id.result);

        login.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                database();
                
            }
        });
    }

    protected void database() {
                
      // Set the text and call the connect function. 
        txt.setText("Connecting...");
      //call the method to run the data retreival
        txt.setText(getServerData(KEY_121));
      }
    public static final String KEY_121 = "http://10.0.2.2/androidapp/index.php"; //i use my real ip here



    private String getServerData(String returnString) {
       
       InputStream is = null;
       
       String result = "";
        //the year data to send
       user = euser.getText().toString();
       pass =  epass.getText().toString();
        if(user == "Test" && pass == "test")
        {
            
        txt.setText("Login Successfully");
        }
        else
        {
            txt.setText("Login Failed");
        }
      
       
        //http post
        try{
            
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("UserName", user));
            nameValuePairs.add(new BasicNameValuePair("Pwd", pass));
            
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(KEY_121);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();

        }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
        }

        //convert response to string
        try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                }
                is.close();
                result=sb.toString();
                
        }catch(Exception e){
                Log.e("log_tag", "Error converting result "+e.toString());
        }
        //parse json data
        
        return result;
    }   


    }
 
Log cat:
Code:
07-16 12:19:53.897: D/gralloc_goldfish(737): Emulator without GPU emulation detected.
07-16 12:19:54.137: W/TextLayoutCache(737): computeValuesWithHarfbuzz -- need to force to single run
07-16 12:20:02.186: D/AndroidRuntime(737): Shutting down VM
07-16 12:20:02.186: W/dalvikvm(737): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
07-16 12:20:02.207: E/AndroidRuntime(737): FATAL EXCEPTION: main
07-16 12:20:02.207: E/AndroidRuntime(737): java.lang.NullPointerException
07-16 12:20:02.207: E/AndroidRuntime(737):     at Com.User.UserName.database(UserName.java:60)
07-16 12:20:02.207: E/AndroidRuntime(737):     at Com.User.UserName$1.onClick(UserName.java:51)
07-16 12:20:02.207: E/AndroidRuntime(737):     at android.view.View.performClick(View.java:3480)
07-16 12:20:02.207: E/AndroidRuntime(737):     at android.view.View$PerformClick.run(View.java:13983)
07-16 12:20:02.207: E/AndroidRuntime(737):     at android.os.Handler.handleCallback(Handler.java:605)
07-16 12:20:02.207: E/AndroidRuntime(737):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-16 12:20:02.207: E/AndroidRuntime(737):     at android.os.Looper.loop(Looper.java:137)
07-16 12:20:02.207: E/AndroidRuntime(737):     at android.app.ActivityThread.main(ActivityThread.java:4340)
07-16 12:20:02.207: E/AndroidRuntime(737):     at java.lang.reflect.Method.invokeNative(Native Method)
07-16 12:20:02.207: E/AndroidRuntime(737):     at java.lang.reflect.Method.invoke(Method.java:511)
07-16 12:20:02.207: E/AndroidRuntime(737):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-16 12:20:02.207: E/AndroidRuntime(737):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-16 12:20:02.207: E/AndroidRuntime(737):     at dalvik.system.NativeStart.main(Native Method)
07-16 12:25:02.336: I/Process(737): Sending signal. PID: 737 SIG: 9
 
Php code:

Code:
mysql_connect("localhost","root","");
mysql_select_db("db_androidapp");

$UserName = $_REQUEST['UserName'];
$Pwd = $_REQUEST['Pwd'];

$query_LoginDetails = "SELECT * FROM tblUserDetails WHERE UserName='$UserName' and Password='$Pwd'";
$rsLoginDetails = mysql_query($query_LoginDetails);
if(mysql_num_rows($rsLoginDetails) > 0)
{
$output = 'Login Success.';
}
else
    {
    $output = 'Login Failed.';
    }

print(json_encode($output));
mysql_close();
?>
 
Back
Top Bottom