so I have an activity with radiobuttons a datepicker and a timepicker that appear when you click two different buttons. Then I have another button underneath that puts text in a textview with the radio button selected, the day and time displayed on the bottom of the screen. The application stops running when I click the third button. The timepicker and the datepicker work just fine but when I click on the third button it crashes.
package net.androidbootcamp.shepherdschurchapp;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import java.text.DateFormat;
import java.util.Calendar;
public class Study extends AppCompatActivity {
private TextView reservation;
private String time = " ";
private String day = " ";
@Override
protected void onCreate(Bundle savedInstanceState) {
//VARIABLES FOR RADIO BUTTONS
final RadioButton oneOnOne =
(RadioButton)findViewById(R.id.oneonone);
final RadioButton smallGroup =
(RadioButton)findViewById(R.id.smallgroup);
final RadioButton largeGroup =
(RadioButton)findViewById(R.id.largegroup);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_study);
//VIEW ICON LAUNCHER
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.mipmap.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
//
reservation =
(TextView)findViewById(R.id.txtReservation);
Button button1 = (Button)findViewById(R.id.btnDate);
Button button2 = (Button)findViewById(R.id.btnTime);
Button convert = (Button)findViewById(R.id.appointment);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new TimePickerDialog(Study.this, t,
b.get(Calendar.HOUR_OF_DAY), b.get(Calendar.MINUTE),
false).show();
} //end onClick
}); //End setOnClickListener
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DatePickerDialog(Study.this, d,
c.get(Calendar.YEAR), c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH)).show();
} //end onClick
}); //End setOnClickListener
convert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(oneOnOne.isChecked()) {
reservation.setText("Your one-on-one bible
study is set for: " + day + " at " + time + ".");
}
if(smallGroup.isChecked()) {
reservation.setText("Your small group bible
study is set for: " + day + " at " + time + ".");
}
if(largeGroup.isChecked()) {
reservation.setText("Your large group bible
study is set for: " + day + " at " + time + ".");
}
}
});
} // END ONCREATE
Calendar c = Calendar.getInstance();
Calendar b = Calendar.getInstance();
DateFormat fmtDate = DateFormat.getDateInstance();
DatePickerDialog.OnDateSetListener d = new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int
month, int dayOfMonth) {
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
day = fmtDate.format(c.getTime());
}
};
TimePickerDialog.OnTimeSetListener t = new
TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
b.set(Calendar.HOUR_OF_DAY, hourOfDay);
b.set(Calendar.MINUTE, minute);
String ampm;
int hour = hourOfDay;
if (hourOfDay > 12) {
hour -= 12;
}
if (hourOfDay >= 12) {
ampm = "PM";
}
else {
ampm = "AM";
}
if(hourOfDay < 7|| hourOfDay > 23){
Toast.makeText(Study.this, "We only do bible
study between 7 am and 11 pm", Toast.LENGTH_LONG).show();
}
else {
time = hour + ":" + minute + " " + ampm;
}
}
};
}