Kardo Kamal Kardo Kamal - 25 days ago 5x
Android Question

Android studio - timer

I was just practicing with Android Studio, and I decided to use the

in the palette.

I added it to my XML layout but when I want to reference it in my
, it gives me an error and no, I haven't misspelled the id. Can someone explain how this works? Thanks.

public class MainActivity extends AppCompatActivity {

private TimePicker timePicker1;

protected void onCreate(Bundle savedInstanceState) {

// Heres when I tried to reference it
timePicker1 = (TimePicker) findViewById(R.layout.timePicker);

timePicker1 = (TimePicker) findViewById(R.**id**.timePicker);

assuming timePicker is the id of your timepicker. You should double check it. However, the reference inside findViewById will be R.id.****. that's a must.

This is your problem. Peace.