Jackson E Jackson E - 13 days ago 7
Java Question

How do I recieve the time from a TimePicker and put it into a variable?

I strongly appreciate any and all help I can get

API 21

1)My timePicker (named timeSelector) is supposed to be interacted with

2)Then when the button is clicked it is supposed to take the timeSelector's hour and minute into two variables.

However, I am really struggling with it, which is frustrating because it seems relatively straightforward.

Sources I Have Looked At:



My code:


TimePicker myPick =(TimePicker) findViewById(R.id.timeSelector);
int myhour = myPick.getCurrentHour();
int myminute = myPick.getCurrentMinute();



Error Image


I really wanna thank everyone that helps me out in advance. I'm confident that as I learn and practice more that this amateur will become a pro!

Answer

Change the import statement for TimePicker class to android.widget.TimePicker, it looks like you have a class with the same name in your project.