0

I am inserting my data in MySql, and the data is inserting successfully. But i am not able to Intent to different Activity after the successful operation.
Here is my code :

public void registerfinish(View view) {
    ...
    new finalRegister().execute();
}

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

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        ...
    }

    /**
     * getting All products from url
     * */
    protected String doInBackground(String... args) {

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        ...
        // getting JSON Object
        // Note that create product url accepts POST method
        JSONObject json = null ;

        try {
            json = jsonParser.makeHttpRequest(url,
                    "GET", params);
        } catch (JSONException e) {
            e.printStackTrace();
        }



        // check for success tag

        try {
            // check log cat fro response
            Log.d("Create Response", json.toString());
            success = json.getInt(TAG_SUCCESS);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (success == 1) {
                // successfully created product
                Intent i = new Intent(Register2ndStep.this, FinalScreen.class);
                startActivity(i);

                // closing this screen
                //finish();
            } else {
                ...
            }
        return null;
    }
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        }
    }

}

Logcat:

Caused by: java.lang.NullPointerException
        at wolverine.example.com.btp_scientist.Register2ndStep$finalRegister.doInBackground(Register2ndStep.java:220)
        at wolverine.example.com.btp_scientist.Register2ndStep$finalRegister.doInBackground(Register2ndStep.java:173)

Register2ndStep.java:220:  Log.d("Create Response", json.toString())
Register2ndStep.java:173:   class finalRegister extends AsyncTask<String, String, String> 
2

1 Answer 1

0

Just move your intent code to onPostExecute method:

 protected void onPostExecute(String file_url) {
         Intent i = new Intent(Register2ndStep.this, FinalScreen.class);
         startActivity(i);
         pDialog.dismiss();
   }
3
  • Same result...The Application is crashing Jul 7, 2015 at 8:00
  • Yes i did. But, i think my problem is in json.toString() which probably giving error. Jul 7, 2015 at 8:47
  • when you calling jsonParser.makeHttpRequest your sending param as argument. Check jsonParser or params or 'json if any of them is null, do a debug or put Log to print in console.
    – Pankaj
    Jul 7, 2015 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.