1

enter image description here

I am trying to make a login and registration activity login system works fine with same method but in register system it gives the error and i cant find whats the error is as in logcat and my code is

public class Register extends Activity implements OnClickListener {

private Button btnLinkToLogin;
private EditText user, pass;
private Button mRegister;
private ProgressDialog pDialog;

JSONParser jsonParser = new JSONParser();

private static final String LOGIN_URL = "http://http://portfolio.webuda.com/register.php";

private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";


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

    user = (EditText) findViewById(R.id.username);
    pass = (EditText) findViewById(R.id.password);

    mRegister = (Button) findViewById(R.id.register);
    mRegister.setOnClickListener(this);
}


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    new CreateUser().execute();
}

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

    /**
     * Before starting background thread Show Progress Dialog
     */
    boolean failure = false;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Register.this);
        pDialog.setMessage("Creating User...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
        // Check for success tag
        int success;
        String username = user.getText().toString();
        String password = pass.getText().toString();
        try {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("username", username));
            params.add(new BasicNameValuePair("password", password));

            Log.d("request!", "starting");

            //Posting user data to script
            JSONObject json = jsonParser.makeHttpRequest(
                    LOGIN_URL, "POST", params);

            // full json response
            Log.d("Login attempt", json.toString());

            // json success element
            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                Log.d("User Created!", json.toString());
                Intent ii = new Intent(Register.this,HomeActivity.class);
                finish();
                startActivity(ii);
                return json.getString(TAG_MESSAGE);
            } else {
                Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                return json.getString(TAG_MESSAGE);

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

        return null;

    }

    protected void onPostExecute(String file_url) {

        pDialog.dismiss();
        if (file_url != null) {
            Toast.makeText(Register.this, file_url, Toast.LENGTH_LONG).show();
        }
    }
}
}
blaze bnayak
  • 123
  • 1
  • 11
  • The actual log would be more useful than a screenshot. By the stacktrace you can tell you have a NPE in the `doInBackground()` method while trying to call some method of `JSONObject` that is returning string, most probably, `toString()`. I assume your `JSONObject` instance is null, so you better check you parser. – Danail Alexiev Sep 25 '15 at 18:08

0 Answers0