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 8454651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:04:55+00:00 2026-06-10T12:04:55+00:00

I am building an app that needs to connect to a PHP API on

  • 0

I am building an app that needs to connect to a PHP API on a websever to get user credentials from a mySQL database. The API will return a JSON object as a result of the login.

I followed a tutorial online and it built everything on the main thread so I am trying to do Async Task. However I can’t get it to work and I keep getting a NullPointerException. The app spends about 5 minutes attempt to connect to my WAMP server and then just shuts down. Does it take that long to connect to servers to simulate poor network conditions?

The code is here:

    private class ProcessLogin extends AsyncTask<Void, String, JSONObject> {
    @Override
    protected JSONObject doInBackground(Void... urls) {

      inputEmail = (EditText) findViewById(R.id.loginEmail);
      inputPassword = (EditText) findViewById(R.id.loginPassword);
      btnLogin = (Button) findViewById(R.id.btnLogin);
      btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
      loginErrorMsg = (TextView) findViewById(R.id.login_error);

      String email = inputEmail.getText().toString();
      String password = inputPassword.getText().toString();

      publishProgress("Attempting to authenticate");

      JSONObject json = userFunction.loginUser(email, password);

       return json;
     }

    @Override
    protected void onPostExecute(JSONObject json) {

        publishProgress("Response received");

        try {
            if (json.getString(KEY_SUCCESS) != null) {
                publishProgress("correct username/password");
            }
            else {
                publishProgress("Incorrect username/password");
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    /* (non-Javadoc)
     * @see android.os.AsyncTask#onProgressUpdate(Progress[])
     */
    @Override
    protected void onProgressUpdate(String... values) {
     super.onProgressUpdate(values);
        // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
        loginErrorMsg = (TextView) findViewById(R.id.login_error);
        loginErrorMsg.setText(values[0]);
     }
  }

   // Login button Click Event
   public void beginLogin(View view) {
     new ProcessLogin().execute();
   }

My log cat error is here:

08-29 20:19:50.462: E/AndroidRuntime(1287): FATAL EXCEPTION: main
08-29 20:19:50.462: E/AndroidRuntime(1287): java.lang.NullPointerException
08-29 20:19:50.462: E/AndroidRuntime(1287):     at             com.example.onepass.LoginActivity$ProcessLogin.onPostExecute(LoginActivity.java:75)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at com.example.onepass.LoginActivity$ProcessLogin.onPostExecute(LoginActivity.java:1)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at android.os.AsyncTask.finish(AsyncTask.java:631)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at android.os.Looper.loop(Looper.java:137)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at java.lang.reflect.Method.invokeNative(Native Method)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at java.lang.reflect.Method.invoke(Method.java:511)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-29 20:19:50.462: E/AndroidRuntime(1287):     at dalvik.system.NativeStart.main(Native Method)

I have just started coding with Android SDK so if the error is really obvious, I apologize and appreciate your pointers.

Thanks

  • 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-10T12:04:57+00:00Added an answer on June 10, 2026 at 12:04 pm

    Error lies in line 75 of LoginActivity.java as stack track tells:

    at
    com.example.onepass.LoginActivity$ProcessLogin.onPostExecute(LoginActivity.java:75)

    Since you did not provide line numbering, my blind guess is your json variable passed to onPostExecute() is simply null. As you assume it is always valid (which is in 99% cases wrong assumption), you try to call getString() on nulled object, hence the NPE.

    Workaround is to check if json is not null prior using it, which is always a good habit

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

Sidebar

Related Questions

I'm building a Rails app that needs to connect to a custom TCP data
I'm building a desktop app that needs to communicate with a MS Access database.
I've started building an android app that will connect to a sql server and
So I'm building an app that needs to know the location of the Box
I am building an iPhone app that will need to display info primarily in
I am building an app that uses the fine Urban Airship api to send
I'm currently building an app that needs to be runnable on Tiger, Leopard and
I'm building and Android app that needs to go through steps like a wizard.
I'm building a rails app that communicates with other servers via ftp. The user
I'm building a facebook connect app to publish content to user's streams. In order

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.