Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6552473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:27:50+00:00 2026-05-25T12:27:50+00:00

I have some code that gets two Time Picker’s content and displays them individually

  • 0

I have some code that gets two Time Picker’s content and displays them individually in TextViews, but when I go to calculate the difference between the two and display it in a separate TextView my app crashes.
Here’s some of the code:

    private TextView mShiftLength;

private TextView mTimeDisplay;
private Button mPickTime;

private TextView mTimeDisplayEnd;
private Button mPickTimeEnd;

    private void calcShiftLength() {
    int mStartTime = Integer.parseInt(mTimeDisplay.getText().toString());
    int mEndTime = Integer.parseInt(mTimeDisplayEnd.getText().toString());

    int shiftLength = mEndTime - mStartTime;

    mShiftLength.setText(Integer.toString(shiftLength));
}

    private void updateDisplay() {
    mTimeDisplay.setText(new StringBuilder().append(pad(mHour)).append(":")
            .append(pad(mMinute)));
}

private void updateDisplayEnd() {
    mTimeDisplayEnd.setText(new StringBuilder().append(pad(mHour))
            .append(":").append(pad(mMinute)));
}

Edit: logcat of error. Sorry I don’t know much about Android really, I hope this is all you were after.

09-13 03:01:39.744: INFO/ActivityManager(59): Starting activity:
 Intent { act=android.intent.action.MAIN
 cat=[android.intent.category.LAUNCHER] flg=0x10000000
 cmp=MultipleTimePickers.UI/.MultipleTimePickers } 09-13 03:01:39.803:
 DEBUG/AndroidRuntime(331): Shutting down VM 09-13 03:01:39.813:
 DEBUG/dalvikvm(331): Debugger has detached; object registry had 1
 entries 09-13 03:01:40.044: INFO/AndroidRuntime(331): NOTE: attach of
 thread 'Binder Thread #3' failed 09-13 03:01:40.174:
 INFO/ActivityManager(59): Start proc MultipleTimePickers.UI for
 activity MultipleTimePickers.UI/.MultipleTimePickers: pid=338
 uid=10050 gids={} 09-13 03:01:41.364: DEBUG/AndroidRuntime(338):
 Shutting down VM 09-13 03:01:41.364: WARN/dalvikvm(338): threadid=1:
 thread exiting with uncaught exception (group=0x4001d800) 09-13
 03:01:41.393: ERROR/AndroidRuntime(338): FATAL EXCEPTION: main 09-13
 03:01:41.393: ERROR/AndroidRuntime(338): java.lang.RuntimeException:
 Unable to start activity
 ComponentInfo{MultipleTimePickers.UI/MultipleTimePickers.UI.MultipleTimePickers}:
 java.lang.NumberFormatException: unable to parse '03:01' as integer
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.app.ActivityThread.access$2300(ActivityThread.java:125) 09-13
 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.os.Handler.dispatchMessage(Handler.java:99) 09-13
 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.os.Looper.loop(Looper.java:123) 09-13 03:01:41.393:
 ERROR/AndroidRuntime(338):     at
 android.app.ActivityThread.main(ActivityThread.java:4627) 09-13
 03:01:41.393: ERROR/AndroidRuntime(338):     at
 java.lang.reflect.Method.invokeNative(Native Method) 09-13
 03:01:41.393: ERROR/AndroidRuntime(338):     at
 java.lang.reflect.Method.invoke(Method.java:521) 09-13 03:01:41.393:
 ERROR/AndroidRuntime(338):     at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-13
 03:01:41.393: ERROR/AndroidRuntime(338):     at
 dalvik.system.NativeStart.main(Native Method) 09-13 03:01:41.393:
 ERROR/AndroidRuntime(338): Caused by: java.lang.NumberFormatException:
 unable to parse '03:01' as integer 09-13 03:01:41.393:
 ERROR/AndroidRuntime(338):     at
 java.lang.Integer.parse(Integer.java:433) 09-13 03:01:41.393:
 ERROR/AndroidRuntime(338):     at
 java.lang.Integer.parseInt(Integer.java:422) 09-13 03:01:41.393:
 ERROR/AndroidRuntime(338):     at
 java.lang.Integer.parseInt(Integer.java:382) 09-13 03:01:41.393:
 ERROR/AndroidRuntime(338):     at
 MultipleTimePickers.UI.MultipleTimePickers.calcShiftLength(MultipleTimePickers.java:70)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 MultipleTimePickers.UI.MultipleTimePickers.onCreate(MultipleTimePickers.java:66)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     at
 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
 09-13 03:01:41.393: ERROR/AndroidRuntime(338):     ... 11 more 09-13
 03:01:41.424: WARN/ActivityManager(59):   Force finishing activity
 MultipleTimePickers.UI/.MultipleTimePickers 09-13 03:01:42.035:
 WARN/ActivityManager(59): Activity pause timeout for
 HistoryRecord{44e7de98 MultipleTimePickers.UI/.MultipleTimePickers}
 09-13 03:01:48.883: DEBUG/dalvikvm(182): GC_EXPLICIT freed 100 objects
 / 4296 bytes in 163ms 09-13 03:01:53.740: WARN/ActivityManager(59):
 Activity destroy timeout for HistoryRecord{44e7de98
 MultipleTimePickers.UI/.MultipleTimePickers} 09-13 03:01:54.034:
 DEBUG/dalvikvm(269): GC_EXPLICIT freed 249 objects / 11840 bytes in
 253ms

Here’s the final working code, thanks for everyone’s help:

    private void calcShiftLength() {
    String[] mStartTime = mTimeDisplay.getText().toString().split(":");
    String[] mEndTime = mTimeDisplayEnd.getText().toString().split(":");

    int mStartHour = Integer.parseInt(mStartTime[0].toString());
    int mStartMinute = Integer.parseInt(mStartTime[1].toString());

    int mEndHour = Integer.parseInt(mEndTime[0].toString());
    int mEndMinute = Integer.parseInt(mEndTime[1].toString());

    int mShiftLengthHour = mEndHour - mStartHour;
    int mShiftLengthMinute = mEndMinute - mStartMinute;

    mShiftLength.setText(new StringBuilder().append(pad(mShiftLengthHour)).append(":").append(pad(mShiftLengthMinute)));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:27:50+00:00Added an answer on May 25, 2026 at 12:27 pm
    NumberFormatException: unable to parse '03:01' as integer
    

    Try using split method of the string, and then parse each string as Integer. And its alway best to catch the NumberFormatException when doing Integer.parseInt

    http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split%28java.lang.String%29

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
If have a piece of code that gets some data from a sql database
I have some code that will be accessed from two threads: class Timer{ public:
I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general
I have some code that effectively does this : File file = new File(C:\\Program
I have some code that I am putting in the code-behind of a master

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.