Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Bug *QueryResults#toArray ClassCastException

Joined
Apr 27, 2019
Messages
11
RuneMate version: 2.99.7

Affected games: OSRS (probably all, but I'm only using it here)

Code used:
Code:
Inventory.newQuery().names(inventoryItem.getDefinition().getName()).results().toArray();

Stack trace:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lcom.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;

Comments:
This exception has occurred any time I've used any QueryResults object's toArray method. Yes, I do realize there is very little reason to cast QueryResults to an array. Found while quickly doing something to test some code.
 
Java Warlord
Joined
Nov 17, 2014
Messages
4,906
Read up how the toArray method works, you‘ll have to pass an array of the type youre expecting (SpriteItem)
 
Joined
Apr 27, 2019
Messages
11
I'm not as familiar with Java as I am with C#, but my understanding of the Java variant of toArray is that if no array is passed, it returns Object[]. In the case I was working with, I didn't care what the objects were, so I just used toArray() rather than toArray(spriteItem[]). This works as expected in other spots I'm using toArray(), such as:
Code:
for (Npc n : npcs) {
    Object[] actions = n.getDefinition().getActions().toArray();
    ...
In the case where I'm getting the error, I was actually doing some other stuff after the toArray related to array processing, and assigning a value from a property of the array itself to an integer, completely unrelated to SpriteItem.
 
Top