Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8176069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:01:16+00:00 2026-06-06T23:01:16+00:00

This activity is used for login. It post the username and password to a

  • 0

This activity is used for login.
It post the username and password to a PHP verify file by “GET” which will a response(either SUCCESS or FAILED)would be got.
But it can only show “error occure” (neither SUCCESS nor FAILED)
here are the code:

public class Login extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    findViewsById();
    setListeners();
}
private Button btn_login;
private EditText edt_username;
private EditText edt_password;

private void findViewsById() {
    edt_username = (EditText) findViewById(R.id.edt_username);
    edt_password = (EditText) findViewById(R.id.edt_password);
    btn_login = (Button) findViewById(R.id.btn_login);              
}


private void setListeners(){
    btn_login.setOnClickListener(login);
}
private Button.OnClickListener login = new Button. OnClickListener() {

public void onClick(View v) {
   new startLogin().execute();      
}



};

private class startLogin extends AsyncTask <Void, Void, Void> {

    String result;
    String url = "http://www.abc.com/verify.php";
    String fail = "FAILED";
    String error = "error";
    final ProgressDialog progDlg = new ProgressDialog(Login.this);

    String username = edt_username.getText().toString();
    String password = edt_password.getText().toString();


    protected void onPreExecute() {
        super.onPreExecute();

        progDlg.setTitle("Please wait");
        progDlg.setMessage("Loading...");
        progDlg.setIcon(android.R.drawable.ic_dialog_info);
        progDlg.setCancelable(false);
        progDlg.show();


        //add username and password to the site

        url += "?username=" + username;
        url += "&password="  + password;    

    }

    @Override
    protected Void doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        HttpResponse httpResponse = null;
        try {



            HttpGet httpGet = new HttpGet (url) ;
            httpResponse = new DefaultHttpClient().execute (httpGet);

            if(httpResponse.getStatusLine().getStatusCode() == 200){      
                    result = EntityUtils.toString(httpResponse.getEntity());     
                }    
                else{                           
                    //connection error    
                    result = error;
                }    


        } catch  (ClientProtocolException e) {
               e.printStackTrace();

           } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }catch (Exception e){
                        e.printStackTrace();
                        }

        return null;
    }

    protected void onPostExecute(Void unused){

        if (result == fail) {
            progDlg.cancel();
            Toast.makeText(Login.this, R.string.fail, Toast.LENGTH_SHORT).show();  //R.string.fail = "username or password is wrong"
        } else if (result == error) {
            progDlg.cancel();
            Toast.makeText(Login.this, R.string.error, Toast.LENGTH_SHORT).show(); //R.string.error = "there is a connection error"
        }
        else if (result == "SUCCESS"){
            progDlg.cancel();
            Intent it = new Intent ();
            it.setClass (Login.this, Main.class);
            startActivity (it);

        } else{
            progDlg.cancel();
            Toast.makeText(Login.this, "error occure", Toast.LENGTH_SHORT).show();
        }

    }


}}

Here are the verify file:

<?php
$username = $_GET["username"];
$password = $_GET["password"];
$ourFileName = "users/" . $username . ".txt";
    if (file_exists($ourFileName))
     {
    $fh = fopen($ourFileName, 'r');
$theData = fread($fh, 1024);
fclose($fh);

if ($password == $theData)
{
    echo SUCCESS;
}  else
{
    echo FAILED;
}
    }else  {
            echo FAILED;}
     ?>

LogCat

07-05 13:10:57.065: W/ActivityThread(274): Application com.android.safe is waiting for the debugger on port 8100...
07-05 13:10:57.085: I/System.out(274): Sending WAIT chunk
07-05 13:10:57.155: I/dalvikvm(274): Debugger is active
07-05 13:10:57.285: I/System.out(274): Debugger has connected
07-05 13:10:57.285: I/System.out(274): waiting for debugger to settle...
07-05 13:10:57.486: I/System.out(274): waiting for debugger to settle...
07-05 13:10:57.685: I/System.out(274): waiting for debugger to settle...
07-05 13:10:57.885: I/System.out(274): waiting for debugger to settle...
07-05 13:10:58.095: I/System.out(274): waiting for debugger to settle...
07-05 13:10:58.295: I/System.out(274): waiting for debugger to settle...
07-05 13:10:58.495: I/System.out(274): waiting for debugger to settle...
07-05 13:10:58.695: I/System.out(274): debugger has settled (1326)
07-05 13:10:58.985: D/dalvikvm(274): GC_EXTERNAL_ALLOC freed 805 objects / 58072 bytes in 43ms
07-05 13:10:59.255: D/dalvikvm(274): GC_EXTERNAL_ALLOC freed 222 objects / 10616 bytes in 42ms
07-05 13:11:45.615: W/KeyCharacterMap(274): No keyboard for id 0
07-05 13:11:45.615: W/KeyCharacterMap(274): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
07-05 13:12:05.345: D/dalvikvm(274): GC_FOR_MALLOC freed 6458 objects / 265088 bytes in 138ms
07-05 13:12:08.036: W/System.err(274): java.lang.IllegalArgumentException: Illegal character in query at index 52: http://panel.o-safe.net/vb_verify.php?username=guest &password=guest
07-05 13:12:08.046: W/System.err(274):  at java.net.URI.create(URI.java:970)
07-05 13:12:08.046: W/System.err(274):  at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
07-05 13:12:08.046: W/System.err(274):  at com.android.safe.Login$startLogin.doInBackground(Login.java:100)
07-05 13:12:08.056: W/System.err(274):  at com.android.safe.Login$startLogin.doInBackground(Login.java:1)
07-05 13:12:08.056: W/System.err(274):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-05 13:12:08.056: W/System.err(274):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-05 13:12:08.066: W/System.err(274):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-05 13:12:08.066: W/System.err(274):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-05 13:12:08.066: W/System.err(274):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-05 13:12:08.066: W/System.err(274):  at java.lang.Thread.run(Thread.java:1096)
07-05 13:12:08.076: D/AndroidRuntime(274): Shutting down VM
07-05 13:12:08.076: W/dalvikvm(274): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-05 13:12:08.116: E/AndroidRuntime(274): FATAL EXCEPTION: main
07-05 13:12:08.116: E/AndroidRuntime(274): java.lang.NullPointerException
07-05 13:12:08.116: E/AndroidRuntime(274):  at com.android.safe.Login$startLogin.onPostExecute(Login.java:127)
07-05 13:12:08.116: E/AndroidRuntime(274):  at com.android.safe.Login$startLogin.onPostExecute(Login.java:1)
07-05 13:12:08.116: E/AndroidRuntime(274):  at android.os.AsyncTask.finish(AsyncTask.java:417)
07-05 13:12:08.116: E/AndroidRuntime(274):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
07-05 13:12:08.116: E/AndroidRuntime(274):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
07-05 13:12:08.116: E/AndroidRuntime(274):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 13:12:08.116: E/AndroidRuntime(274):  at android.os.Looper.loop(Looper.java:123)
07-05 13:12:08.116: E/AndroidRuntime(274):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-05 13:12:08.116: E/AndroidRuntime(274):  at java.lang.reflect.Method.invokeNative(Native Method)
07-05 13:12:08.116: E/AndroidRuntime(274):  at java.lang.reflect.Method.invoke(Method.java:521)
07-05 13:12:08.116: E/AndroidRuntime(274):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-05 13:12:08.116: E/AndroidRuntime(274):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-05 13:12:08.116: E/AndroidRuntime(274):  at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:01:18+00:00Added an answer on June 6, 2026 at 11:01 pm

    please make sure that the PHP script works fine by checking the same on a browser

    i noticed the following errors in your code

    • you compare two strings using == rather than equals method in ‘String’ class. so change all == result comparisons to equals in onPostExecute method.

    updated code

    protected void onPostExecute(Void unused){
    
        if (result.equals(fail)) {
            progDlg.cancel();
            Toast.makeText(Login.this, R.string.fail, Toast.LENGTH_SHORT).show();  //R.string.fail = "username or password is wrong"
        } else if (result.equals(error)) {
            progDlg.cancel();
            Toast.makeText(Login.this, R.string.error, Toast.LENGTH_SHORT).show(); //R.string.error = "there is a connection error"
        }
        else if (result.equals("SUCCESS")){
            progDlg.cancel();
            Intent it = new Intent ();
            it.setClass (Login.this, Main.class);
            startActivity (it);
    
        } else{
            progDlg.cancel();
            Toast.makeText(Login.this, "error occure", Toast.LENGTH_SHORT).show();
        }
    
    }
    
    • One another thing. you can return values from ‘doInBackGround’ method to onPostExecute method. what i mean is, it is not necessary that you always make changes to global variables. here variable result. for this you need to change the AsyncTask signature while extending it.

    so change

    private class startLogin extends AsyncTask <Void, Void, Void>
    

    to

    private class startLogin extends AsyncTask <Void, Void, String>
    

    the third parameter is the Result type. Now you have to change the following methods to adapt the above change

    protected Void doInBackground(Void... arg0) {
    

    to

    protected String doInBackground(Void... arg0) {
    

    and

    protected void onPostExecute(Void unused){
    

    to

    protected void onPostExecute(String result){
    

    this will help you to return status strings directly from doInBackGround method to onPostExecute

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the scenario: User has a main activity used for UI. Program needs
Hi I have an application which after login, loads a main activity which contains
I used to get the Login Time of a user when he Logsin at
So this is currently how my app is set up: 1.) Login Activity. 2.)
RESOLVED! The problem is that I used this.findViewById, but I will use dialog.findViewById. TNX
I have one SubjectTabActivity and i need to show listview on this activity. But
I have an activity that starts after a certain time. Once this activity starts,
I'm binding to Service by this way: Activity class: ListenLocationService mService; @Override public void
This is my activity oncreate() method. I set a positive button ok with a
what is the logic behind this on this website last activity: 1 min ago

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.