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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:58:54+00:00 2026-06-12T19:58:54+00:00

I am working on an Android project in that i need to send the

  • 0

I am working on an Android project in that i need to send the login data to an online database.
For that asynctask class is used.

but i got innerset exceptions in logcat and a force close.

Here is my code

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {
    EditText un,pw;
    Button ok;
    String res;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        un=(EditText)findViewById(R.id.u_name);
        pw=(EditText)findViewById(R.id.passwd);
        ok=(Button)findViewById(R.id.btnlogin);

        ok.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
                // TODO Auto-generated method stub
                GetData task = new GetData();
                task.execute();


            }
        });
    }

    private class GetData extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... urls) {
            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
            postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
            //String valid = "1";
            String response = null;
                try {
                    response = CustomHttpClient.executeHttpPost("http://127.0.0.1/test_login/check.php", postParameters);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                res=response.toString();
               // res = res.trim();
                res= res.replaceAll("\\s+","");                              
                //error.setText(res);
            return response;
        }

        protected void onPostExecute(String result)
        {
        result = res;
               if(result.equals("1"))
               {
                   Toast toast = Toast.makeText(LoginActivity.this, 
                             "LoginSuccess", Toast.LENGTH_LONG);
                   toast.show();
                   Intent n = new Intent(getApplicationContext(),TestActivity.class);
                   startActivity(n);
               }
                else
                {
                    Toast toast = Toast.makeText(LoginActivity.this, 
                         "Login failed", Toast.LENGTH_LONG);
                    toast.show();
                }

        }
    }
}

I got the following logcat errors

10-11 23:43:10.819: E/AndroidRuntime(1335): FATAL EXCEPTION: AsyncTask #1
10-11 23:43:10.819: E/AndroidRuntime(1335): java.lang.RuntimeException: An error occured while executing doInBackground()
10-11 23:43:10.819: E/AndroidRuntime(1335):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.lang.Thread.run(Thread.java:856)
10-11 23:43:10.819: E/AndroidRuntime(1335): Caused by: java.lang.NullPointerException
10-11 23:43:10.819: E/AndroidRuntime(1335):     at com.oranz.epark.LoginActivity$GetData.doInBackground(LoginActivity.java:55)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at com.oranz.epark.LoginActivity$GetData.doInBackground(LoginActivity.java:1)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
10-11 23:43:10.819: E/AndroidRuntime(1335):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-11 23:43:10.819: E/AndroidRuntime(1335):     ... 5 more
  • 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-12T19:58:55+00:00Added an answer on June 12, 2026 at 7:58 pm

    The problem is with your response String being null.

    You are forcing the code to be run even after try catch is executed. So if the executeHttpPost method gets into some kind of problem, ur response string will be null and in the next line you are doing,

     res=response.toString();
    

    where repsonse is actually null and hitting the NPE.

    EDIT

    Change your try catch like this,

            try {
                response = CustomHttpClient.executeHttpPost("http://127.0.0.1/test_login/check.php", postParameters);
            } catch (Exception e) {
                return null;
                e.printStackTrace();
            }
    

    And postExecute,

    protected void onPostExecute(String result)
            {
            result = res;
                    if(result==null)
                    {
      Toast toast = Toast.makeText(LoginActivity.this, 
                                 "Login Failed. Try again", Toast.LENGTH_LONG);
                       toast.show();
                    }
    
                 else  if(result.equals("1"))
                   {
                       Toast toast = Toast.makeText(LoginActivity.this, 
                                 "LoginSuccess", Toast.LENGTH_LONG);
                       toast.show();
                       Intent n = new Intent(getApplicationContext(),TestActivity.class);
                       startActivity(n);
                   }
                    else
                    {
                        Toast toast = Toast.makeText(LoginActivity.this, 
                             "Login failed", Toast.LENGTH_LONG);
                        toast.show();
                    }
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an Android project I'm working on that, ultimately, will require me to
I'm working in a android project the idea is simple: I just need to
I am working on android applications. In my project I need to create Listview.
I am working on a project where I need to make an Android and
I'm working on an Android project (API level 10) which needs to send and
I'm working on a project that utilizes the USB Host capabilities in Android 3.2.
I have dug out an old android project that I was working on a
I'm currently working on a project that's based on Android. Without getting into many
I'm working on an Android project and I need to add buttons to a
Problem Statement:- I am working on the android project in which I need to

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.