Skip to content

Common Errors

CmdrNorthpaw edited this page May 14, 2021 · 2 revisions

Here are some common errors that you may encounter using KInventory, and how to work around them.

UnsupportedOperationExtension

When working with the DefaultedLists that Minecraft generally uses to store the ItemStacks in inventories, you may encounter an UnsupportedOperationException. This happens because Kotlin (quite rightly) sees DefaultedList as a list, and tries to be helpful and add its own functions to be run on a list. The problem is that these conflict with DefaultedList's own functions, and throw this error.

The solution is to use DefaultedList<E>.set(), which is identical to add() except it returns the element that you set. However, it crucially doesn't shadow a Kotlin method, so you can use it without causing an error.

IllegalAccessException

This error occurs when you try to serialize a class with private values in the constructor. While such a class will compile, actually trying to serialize it will make kotlinx.serialization attempt to access a private variable which throws this error. The solution is to modify the access of that variable to either public or internal (internal makes the variable public but only within your code. Other users who depend on your code will not see it).

Clone this wiki locally