Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer #20

Open
gmccobb opened this issue Jan 14, 2020 · 2 comments

Comments

@gmccobb
Copy link

gmccobb commented Jan 14, 2020

The following exception is thrown when starting the foreground service:

java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
at android.os.BaseBundle.getInt(BaseBundle.java:1041)
at android.os.BaseBundle.getInt(BaseBundle.java:1023)
at com.voximplant.foregroundservice.NotificationHelper.buildNotification(NotificationHelper.java:99)
at com.voximplant.foregroundservice.VIForegroundService.onStartCommand(VIForegroundService.java:31)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4087)
at android.app.ActivityThread.access$1800(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

At line 99 of NotificationHelper.java:

int priorityInt = notificationConfig.containsKey("priority") ? notificationConfig.getInt("priority"): Notification.PRIORITY_HIGH;

The exception is thrown because there must be explicit cast to int when downcasting from double.

The proposed fix is to replace line 99 with the following:

int priorityInt = notificationConfig.containsKey("priority") ? (int)notificationConfig.getDouble("priority"): Notification.PRIORITY_HIGH;

I am submitting a PR with the above proposed fix.

Thank you,

gmccobb added a commit to gmccobb/foreground-service-library-test that referenced this issue Jan 14, 2020
…ava.lang.Double cannot be cast to java.lang.Integer

This is the proposed fix for issue voximplant#20, java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer.  Line #99 of NotificationHelper.java is replaced by: int priorityInt = notificationConfig.containsKey("priority") ? (int)notificationConfig.getDouble("priority"): Notification.PRIORITY_HIGH;
@tapioko
Copy link

tapioko commented Apr 21, 2020

How does the double get in there? Sometimes this occurs when I profile the application.

The fix looks good to me.

@hazelf42
Copy link

hazelf42 commented Feb 2, 2021

+1 having this issue. Hope this gets merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants