• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Search is Failing  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1785
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the following error:

java.lang.ClassCastException: com.HourBankWebApp.MFGDate incompatible with java.lang.Comparable

MFGDate Class:



MFGDateList Class:



Code that is generating error(note dateNumber = 1170807):

 
Pete Letkeman
Ranch Foreman
Posts: 917
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a shot in the dark, but:
  • Is your returned data sorted?
  • From what I see, and I could be 100% wrong, comparable is not implemented in your MFGDate class.

  • I think that for accurate results the method Arrays.binarySearch requires that your list be sorted and comparable needs to be implemented in your custom object/class (MFGDate) .
     
    Steve Dyke
    Ranch Hand
    Posts: 1785
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Pete Letkeman wrote:Just a shot in the dark, but:
  • Is your returned data sorted?
  • From what I see, and I could be 100% wrong, comparable is not implemented in your MFGDate class.

  • I think that for accurate results the method Arrays.binarySearch requires that your list be sorted and comparable needs to be implemented in your custom object/class (MFGDate) .


    Excellent. That fixed it. Thanks.
     
    Pete Letkeman
    Ranch Foreman
    Posts: 917
    26
    Android Chrome IntelliJ IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm glad that I could help. All that I ask is you pay it forward when the opportunity presents itself.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!