{"id":2559,"date":"2022-08-30T15:25:52","date_gmt":"2022-08-30T15:25:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/03\/timepicker-getcurrenthour-and-getcurrentminute-not-working-in-android-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:52","modified_gmt":"2022-08-30T15:25:52","slug":"timepicker-getcurrenthour-and-getcurrentminute-not-working-in-android-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/timepicker-getcurrenthour-and-getcurrentminute-not-working-in-android-collection-of-common-programming-errors\/","title":{"rendered":"TimePicker getCurrentHour() and getCurrentMinute() not working in Android-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;ve followed this tutorial http:\/\/developer.android.com\/resources\/tutorials\/views\/hello-timepicker.html to create a time picker, I then created a second one and I&#8217;m attempting to compare the difference between the two. I have the following method and for some reason getCurrentHour() and getCurrentMinute() are not working even though they have been imported as public methods. Here is my method:<\/p>\n<pre><code>private void calcShiftLength() {\nint difHour = mTimeDisplayEnd.getCurrentHour() -mTimeDisplay.getCurrentHour();\nint difMin = mTimeDisplayEnd.getCurrentMinute() - mTimeDisplay.getCurrentMinute();\n\nmShiftLength.setText(new StringBuilder().append(difHour).append(\":\").append(difMin));\n}\n<\/code><\/pre>\n<p>I get the following error code &#8220;The method getCurrentHour() is undefined for the type TextView&#8221; Thanks for any help. Edit:I realised some of the method was set up for testing the error, which I understand the issue I&#8217;m just unsure how to resolve it. Here is an exmaple of my TimePicker&#8217;s being used:<\/p>\n<pre><code>private TimePickerDialog.OnTimeSetListener mTimeSetListener = new     TimePickerDialog.OnTimeSetListener() {\npublic void onTimeSet(TimePicker view, int hourOfDay, int minute) {\n        mHour = hourOfDay;\n        mMinute = minute;\n        updateDisplay();\n    }\n};\nprivate TimePickerDialog.OnTimeSetListener mTimeSetListenerEnd = new TimePickerDialog.OnTimeSetListener() {\n    public void onTimeSet(TimePicker view2, int hourOfDay, int minute) {\n        mHour = hourOfDay;\n        mMinute = minute;\n        updateDisplayEnd();\n    }\n};\n<\/code><\/pre>\n<p>Edit2: Here&#8217;s my declarations:<\/p>\n<pre><code>    private TextView mShiftLength;\n\nprivate TextView mTimeDisplay;\nprivate Button mPickTime;\n\nprivate TextView mTimeDisplayEnd;\nprivate Button mPickTimeEnd;\n\nprivate int mHour;\nprivate int mMinute;\n\nstatic final int TIME_DIALOG_ID = 0;\nstatic final int TIME_DIALOG_IDEND = TIME_DIALOG_ID + 1;\n<\/code><\/pre>\n<p>Edit 3: The following code is meant to convert the hours to an int and then take them away to calculate the difference. I will work with the 24 hour time later I just want to have it working for now. Anyway it is crashing my app at the moment:<\/p>\n<pre><code>    private void calcShiftLength() {\n    int startTime = Integer.parseInt(mTimeDisplay.getText().toString());\n    int endTime = Integer.parseInt(mTimeDisplayEnd.getText().toString());\n    int shiftLength = endTime - startTime;\n\n    mShiftLength.setText(new StringBuilder().append(shiftLength));\n}\n<\/code><\/pre>\n<ol>\n<li>\n<p><code>getCurrentHour()<\/code> method can only be used with widget type <code>TimePicker<\/code>. Please confirm if your are using correct widget. The error clearly says you are trying access it using <code>TextView<\/code> instead.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-03 02:28:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve followed this tutorial http:\/\/developer.android.com\/resources\/tutorials\/views\/hello-timepicker.html to create a time picker, I then created a second one and I&#8217;m attempting to compare the difference between the two. I have the following method and for some reason getCurrentHour() and getCurrentMinute() are not working even though they have been imported as public methods. Here is my method: private [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2559","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2559"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2559\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}