The app is compiled running on the device. But when I try to set the time, an error occurs and the application closes. I suspect something with a timePicker. Plz tell me who knows.

01-03 16: 12: 21.201 27320-27320 / info.doma.budilnik E / AndroidRuntime: FATAL EXCEPTION: main java.lang.NoSuchMethodError: android.widget.TimePicker.getHour at info.doma.budilnik.MainActivity $ 1.onClick ( MainActivity.java:48) at android.view.View.performClick (View.java.73805) at android.view.View $ PerformClick.run (View.java:14822) at android.os.Handler.handleCallback (Handler.java : 642) at android.os.Handler.dispatchMessage (Handler.java:92) at android.os.Looper.loop (Looper.java:137) at android.app.ActivityThread.main (ActivityThread.java 4545) at java .lang.reflect.Method.invokeNative (Native Method) at java.lang.reflect.Method.invoke (Method.javainter11) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main (ZygoteInit.javailiate51) at dalvik.system.NativeStart.main (Native Method) 01-03 16: 12: 21.211 107-174 /? E / atgles: RecordError 0x0 01-03 16: 12: 21.211 237-237 /? W / ActivityManager: Force finishing activity info.doma.budilnik / .MainActivity 01-03 16: 12: 21.231 107-174 /? E / atgles: RecordError 0x0

  • Show what is written in the error? - Paulo Berezini
  • There is a message "An error has occurred in the application" and all no information. - permail
  • The logs should contain the full text of Exception. Find it and show it, please. - tse
  • The error message came out large in the comment window does not fit so it made a screenshot of it above in the question. I can not figure out what should be corrected here. I click on active links, he throws me out then in MainActivity, then in View or Looper, they are created automatically, I don’t understand what needs to be corrected here. - permail
  • added a message in the log to the question text above the code - permail

1 answer 1

The getHour() method of the getHour() class is available starting from API23. If the minimum version of the API (minSDKversion) of your application is less than API23, then you get the NoSuchMethodError exception, which is thrown if you cannot use the method (in this case it is not available at the lower APIs that you have stated in your application).

You can solve this problem by increasing the minimum API of the application to 23, but then your application will not start on devices with OS below Android 6.0, or you may not use this method and get the value you need in another way - for example, use the getCurrentHour() method.

  • Thank you very much. The problem really was that. Sorry I can not vote for the reputation answer is not enough. - permail