Here is my code in which on clicking I am calling AttemptLogin method.
class NewActivity extends AppCompatActivity implements View.OnClickListener {
EditText editEmail, editPassword, editName;
Button btnSignIn, btnRegister;
private ProgressDialog pDialog;
String URL= "https://xyz/restapi/registration";
JSONParser jsonParser=new JSONParser();
int i=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnRegister=(Button)findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(this);
/*btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AttemptLogin attemptLogin= new AttemptLogin();
attemptLogin.execute(editName.getText().toString(),editPassword.getText().toString(),"");
}
});*/
/*btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AttemptLogin().execute();
}
});*/
}
@Override
public void onClick(View v) {
new AttemptLogin().execute();
}
private class AttemptLogin extends AsyncTask<String, String, JSONObject> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(NewActivity.this);
pDialog.setMessage("Attempting for registering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
ArrayList params = new ArrayList();
params.add(new BasicNameValuePair("cust_firstname", "Sai"));
params.add(new BasicNameValuePair("cust_lastname", "Kumar"));
params.add(new BasicNameValuePair("cust_phoneno", "9989219692"));
params.add(new BasicNameValuePair("cust_confirmpass", "Sai@123"));
params.add(new BasicNameValuePair("cust_pass", "Sai@123"));
params.add(new BasicNameValuePair("cust_username", "sai@gmail.com"));
JSONObject json = jsonParser.makeHttpRequest(URL, "POST", params);
return json;
}
protected void onPostExecute(JSONObject result) {
// dismiss the dialog once product deleted
//Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
try {
if (result != null) {
Toast.makeText(getApplicationContext(),result.getString("message"),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
on button click i want to post data directly but getting error as
Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
If there are any nice tutorials for registering details for Async task means please let me know.