Android Question java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean

LUHUANWEI

Member
Licensed User
I am a beginner for B4A, when I debug my app, the UI on the phone is shut down showing"The app is not respone" but on the B4A program side show some errors as below: Kindly pls help to understand what kinds of error on my app. Thanks.

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at b4a.example.main$HandleKeyDelayed.runDirectly(main.java:226)
at b4a.example.main.onKeyDown(main.java:213)
at android.view.KeyEvent.dispatch(KeyEvent.java:2609)
at android.app.Activity.dispatchKeyEvent(Activity.java:2726)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2225)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3953)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3915)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3465)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3518)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3484)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3594)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3492)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3651)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3465)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3518)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3484)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3492)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3465)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3518)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3484)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3627)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3788)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2212)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1853)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1844)
 

Attachments

  • LUNPAN2.0.zip
    4.8 KB · Views: 158
  • mp3 files.zip
    141.2 KB · Views: 182

ilan

Expert
Licensed User
Longtime User
When you debug your app in debuge mode the ide will point ypu to the lines of the code that raises that error.

You should post the code that causes that error so we can help you.
 
Upvote 0

LUHUANWEI

Member
Licensed User
Hi Ilan, thank you for your help.
When I debug my app in deguge mode, the ide did not stop in any line and raise the error, I posted the codes and files needs. Hope can get your support. thank a lots.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Hi Ilan, thank you for your help.
When I debug my app in deguge mode, the ide did not stop in any line and raise the error, I posted the codes and files needs. Hope can get your support. thank a lots.


i dont have b4a in my work but when i open your file in notepad i see that in activity_keypress the "As Boolean" is missing

what keys are you trying to catch? it looks like you have lot of keys in your phone (If KeyCode=25 Or KeyCode=24 Or KeyCode=79 Or KeyCode==85 Then )

this is how the sub should look like: (catching the back key)

B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean

    If KeyCode = KeyCodes.KEYCODE_BACK Then

       '... Some Code

    End If

    Return True
End Sub


btw: KeyCode==85 in b4x you use only one "="

try to remove Sub Activity_KeyPress and debug your app. if it runs then that sub cause the errors
 
Upvote 0

LUHUANWEI

Member
Licensed User
It seam that my problem from Sub Activity_KeyPress(KeyCode As Int) As Boolean, "As Boolean" is missing in my code. Thank you very much for your help!
 
Upvote 0

LUHUANWEI

Member
Licensed User
One more question, How can I stop the Volume+&- actions to the Android system when I used the Volume+&- keys for other functions?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Sorry i dont understand your question. U are catching the keys volume up/down in keypress event and use those keys for a different action BUT u also want to be able to set volume higher/lower? So use 1 key for 2 different actions?
 
Upvote 0

fixit30

Active Member
Licensed User
Longtime User
To stop the volume changing you need to Return True

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then
        'Your code here
        Return True
    Else If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
        'Your code here
        Return True
    End If
End Sub
 
Upvote 0

LUHUANWEI

Member
Licensed User
Two questions:
1.How can I keep the Vollume_Down and Vollume_up still available for my APP when the phone stay in idle?
1.How can I keep the Vollume_Down and Vollume_up still available for my APP when the phone stay in early suspend(when the screen is off)?
Thanks.
 
Upvote 0
Top