6

I have a problem with debugging my code. I'm getting java.lang.NumberFormatException: Invalid int: "" error at line 88 which is Calendar c = Calendar.getInstance();. I dont' understand how the Calendar instance can produce such error.

WakefulReceiverWorker.java:

    Calendar c = Calendar.getInstance();   // <----- line 88
    long newStart = c.getTimeInMillis() + 300000;
    AlarmManager mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, randomInt, intent2,PendingIntent.FLAG_UPDATE_CURRENT);
    mAlarmManager.set(AlarmManager.RTC_WAKEUP, (newStart), pendingIntent);

logcat:

12-13 19:57:01.589    2070-2085/com.example.app W/System.err﹕ java.lang.NumberFormatException: Invalid int: ""
12-13 19:57:01.619    2070-2085/com.example.app W/System.err﹕ at java.lang.Integer.invalidInt(Integer.java:138)
12-13 19:57:01.629    2070-2085/com.example.app W/System.err﹕ at java.lang.Integer.parseInt(Integer.java:359)
12-13 19:57:01.639    2070-2085/com.example.app W/System.err﹕ at java.lang.Integer.parseInt(Integer.java:332)
12-13 19:57:01.639    2070-2085/com.example.app W/System.err﹕ at java.util.Calendar.getHwFirstDayOfWeek(Calendar.java:807)
12-13 19:57:01.639    2070-2085/com.example.app W/System.err﹕ at java.util.Calendar.<init>(Calendar.java:745)
12-13 19:57:01.639    2070-2085/com.example.app W/System.err﹕ at java.util.GregorianCalendar.<init>(GregorianCalendar.java:338)
12-13 19:57:01.649    2070-2085/com.example.app W/System.err﹕ at java.util.GregorianCalendar.<init>(GregorianCalendar.java:239)
12-13 19:57:01.649    2070-2085/com.example.app W/System.err﹕ at java.util.Calendar.getInstance(Calendar.java:1086)
12-13 19:57:01.649    2070-2085/com.example.app W/System.err﹕ at com.example.app.WakefulReceiverWorker.onHandleIntent(WakefulReceiverWorker.java:88)
12-13 19:57:01.659    2070-2085/com.example.app W/System.err﹕ at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
12-13 19:57:01.659    2070-2085/com.example.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 19:57:01.659    2070-2085/com.example.app W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
12-13 19:57:01.659    2070-2085/com.example.app W/System.err﹕ at android.os.HandlerThread.run(HandlerThread.java:60)
13
  • It's not another variable....it's an invalid date in the Calendar. Commented Dec 13, 2013 at 19:14
  • @Elliott Frisch No, variable c is unique in this class. Commented Dec 13, 2013 at 19:15
  • 1
    " Calendar c = Calendar.getInstance(); " are you sure that is line 88? Commented Dec 13, 2013 at 19:17
  • 2
    stackoverflow.com/questions/16936086/… Another similar issue. Commented Dec 13, 2013 at 19:21
  • 4
    Calendar.getHwFirstDayOfWeek isn't a standard java.util.Calendar method. It could be a Huawei implementation bug. Mobile device vendors sometiems override the Android Framework code to work with their specific hardware. Seems like every search for getHwFirstDayOfWeek is an Android Huawei device... Commented Dec 13, 2013 at 19:31

3 Answers 3

3

I've just tested the app on the Samsung Galaxy S3 (i9300) and the error is not present on this device. It seems that it is Huawei's software problem.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

  Calendar calendar = new GregorianCalendar();

Not sure why yours isn't working, but Calendar is an Abstract class, so it might work better if you try GregorianCalendar.

3 Comments

Calendar.getInstance() is not unsafe
Doesn't change anything.
new GregorianCalendar() assumes your users use Gregorian Calendars, but not every country/region uses it.
0

Try instantiating your Calendar this way:

Locale locale = Locale.getDefault();
System.out.println("Locale is : [" + locale + "]"); // make sure there is a default Locale
Calendar calendar = Calendar.getInstance(locale);

----- Update ------
If you go through the stack trace, it looks like this is the culprit:

12-13 19:57:01.639    2070-2085/com.example.app W/System.err﹕ at java.util.Calendar.getHwFirstDayOfWeek(Calendar.java:807)

Because the next line in the stack trace starts parsing the integer, presumably the value returned by getHwFirstDayOfWeek().

1 Comment

You changed variable name, otherwise the code is the same as OP's. How does that help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.