0

Hey guys can you look at my errors, my logcat says it is because i am getting null pointer exception. i don't understand why. I just added a String variable which is "Email" and make the value of my eadd which stands for email address equals to it, then i have these errors now. can you point to me the problem guys?

These are my codes:

**

public class LoginSub extends Activity {
     public static String Email;
    // Progress Dialog
    private ProgressDialog pDialog;

    JSONParser jsonParser = new JSONParser();
    EditText inputEmail;
    EditText inputPassword;
    TextView TextView1;

    // url to create new product
    //private static String url_create_product = "http://student-thesis.netii.net/log_in.php";
    private static String url_create_product = "http://10.0.2.2/TheCalling/log_in.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";

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

        // Edit Text
        inputEmail = (EditText) findViewById(R.id.inputEmail);
        inputPassword = (EditText) findViewById(R.id.inputPassword);


        // Create button
        Button btnLogin = (Button) findViewById(R.id.btnLogin);

        // button click event
        btnLogin.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // creating new product in background thread
                new phpconnect().execute();
            }
        });

        Button btnReg = (Button) findViewById(R.id.btnReg);
        // button click event
        btnReg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(), Register.class);
                startActivity(i);
            }
        });
    }

    /**
     * Background Async Task to Create new product
     * */
    class phpconnect extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(LoginSub.this);
            pDialog.setMessage("Logging in..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {
            String eadd = inputEmail.getText().toString();
            String password = inputPassword.getText().toString();


            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("eadd", eadd));
            params.add(new BasicNameValuePair("password", password));

            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);
                Email.equals(eadd);
                if (success == 1) {
                    // successfully created product
                    Intent i = new Intent(getApplicationContext(), Mapping.class);
                    startActivity(i);
                    // closing this screen
                    finish();
                } else {

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

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            pDialog.dismiss();
        }

    }
}

**

and here's my logcat errors:

**

03-06 22:21:16.428: E/AndroidRuntime(1417): FATAL EXCEPTION: AsyncTask #1
03-06 22:21:16.428: E/AndroidRuntime(1417): java.lang.RuntimeException: An error occured while executing doInBackground()
03-06 22:21:16.428: E/AndroidRuntime(1417):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.lang.Thread.run(Thread.java:856)
03-06 22:21:16.428: E/AndroidRuntime(1417): Caused by: java.lang.NullPointerException
03-06 22:21:16.428: E/AndroidRuntime(1417):     at com.example.projectthesis.LoginSub$phpconnect.doInBackground(LoginSub.java:129)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at com.example.projectthesis.LoginSub$phpconnect.doInBackground(LoginSub.java:1)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
03-06 22:21:16.428: E/AndroidRuntime(1417):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

**

Thank you guys.

1
  • make sure that inputEmail isn't null, this may be the reason you are getting nullexception when trying call getText metho Commented Mar 7, 2013 at 7:01

3 Answers 3

1

Remove this block from doInBackGround()

if (success == 1) {
    // successfully created product
    Intent i = new Intent(LoginSub.this, Mapping.class);
    startActivity(i);
    // closing this screen
    finish();
} else {
  }

And add it in onPostExecute() section

protected void onPostExecute(String file_url) 
{
    // dismiss the dialog once done
    pDialog.dismiss();
    if (success == 1) 
    {
       // successfully created product
       Intent i = new Intent(getApplicationContext(), Mapping.class);
       startActivity(i);
       // closing this screen
       finish();
     } 
     else 
     {
     }
}
Sign up to request clarification or add additional context in comments.

1 Comment

still are you getting exceptions?
0

Some times getApplicationContext() wont provide the exact context values. So pass the Context context; //declare context=this;// assigning next line after setcontextview. then pass the context instead of getApplicationContext() . and check it and also if you want to do any UI updates you are not supposed to do in doinBackground(). You have to do in post execute.

Hope this will help you.

1 Comment

O_o whoooa, i don't understand men, beginners here. :) but i appreciate your answer thank you.
0

I think because this line

new phpconnect().execute();

and

class phpconnect extends AsyncTask<String, String, String> {

You declare AsyncTask with <String, String, String> but you didn't pass any parameter in .exeute();

Moreover that, from your code you don't want any parameter for AsyncTask so you should declare your Asynctask like this

class phpconnect extends AsyncTask<Void, Void, Void> {

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.