B4J Question java.lang.ClassCastException: class java.lang.Double cannot be cast to class java.lang.Integer (java.lang.Double and java.lang.Integer are in module j

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Getting this error on this routine
Code: Copy
'============================================================
Private Sub EvaluatePostFlopStrength(HoleCards As List, BoardCards As List) As ResumableSub
    Dim AllCards As List
    AllCards.Initialize
    For Each c As Object In HoleCards
        AllCards.Add(c)
    Next
    For Each c As Object In BoardCards
        AllCards.Add(c)
    Next

    Wait For (cPokerEvaluator.EvaluateCards(AllCards)) Complete (EvalRes As Map)
    Dim Category As Int = EvalRes.Get(cPokerEvaluator.cResult_Category)

    ' Also check board-only category so bot knows if it is just "playing the board"
    Dim BoardCategory As Int = 0
    If BoardCards.Size >= 3 Then
        Wait For (cPokerEvaluator.EvaluateCards(BoardCards)) Complete (BoardRes As Map)
        BoardCategory = BoardRes.Get(cPokerEvaluator.cResult_Category)
    End If

    Dim Strength As Int = 20

    Select Category
        Case cCAT_ROYAL_FLUSH, cCAT_STRAIGHT_FLUSH
            Strength = 100
        Case cCAT_FOUR_KIND
            Strength = 98
        Case cCAT_FULL_HOUSE
            Strength = 94
        Case cCAT_FLUSH
            Strength = 88
        Case cCAT_STRAIGHT
            Strength = 84
        Case cCAT_THREE_KIND
            Strength = 78
        Case cCAT_TWO_PAIR
            Strength = 68
        Case cCAT_ONE_PAIR
            Strength = 52
        Case cCAT_HIGH_CARD
            Strength = 25
    End Select

    ' If the community board itself already has the same pair/two-pair/trips,
    ' our hole cards aren't helping as much -> reduce confidence
    If BoardCategory > 0 And Category = BoardCategory Then
        Strength = Strength - 22
    End If

    Return Max(5, Min(100, Strength))
End Sub

Seems the Return line Return Max(5, Min(100, Strength)) is causing the problem. On a ResumableSub shouldn't the value be automatically converted

Code: Copy
Error occurred on line: 662 (cPokerBotAI)
java.lang.ClassCastException: class java.lang.Double cannot be cast to class java.lang.Integer (java.lang.Double and java.lang.Integer are in module java.base of loader 'bootstrap')
    at b4j.FridayNightPoker.cpokerbotai$ResumableSub_DecideAction.resume(cpokerbotai.java:211)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:117)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:104)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:162)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:104)
    at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1182)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:1589)
 
The problem with ResumableSub is that it doesn't know what type is expected therefore cannot do any conversions.

Code: Copy
Return Max(5, Min(100, Strength)).As(Int)
Should do the trick. assuming you want an int value.
 
Upvote 1
Back
Top