1

com.soywiz.korinject.AsyncInjector$NotMappedException: Class 'class ChooseCampaign (Kotlin reflection is not available)' doesn't have constructors RequestContext(initialClazz=class ChooseCampaign (Kotlin reflection is not available))

Above exception was threw when I compiled current code. And I dont know how fix it and what does it means.
My code:

textButton {
            position(0, 128)
            text = "Play"
            onClick {
                println("Play")
                launchImmediately {
                    sceneContainer.changeTo<ChooseCampaign>()
                }
            }
        }

How it fix?

Kirill Rakhman
  • 42,195
  • 18
  • 124
  • 148
snaulX
  • 17
  • 7

1 Answers1

2

When using Scenes in KorGE, you are using the korinject dependency injector indirectly.

And that injector requires manual mapping. If you are using Modules, you can configure those mappings at the Module.init method.

Check this sample: https://github.com/korlibs/korge-samples/blob/1771b7ca7f4440e1a368ff4b441e97bf62e08b8d/sample-scenes/src/commonMain/kotlin/main.kt#L15-L23

In your case, once you get the Injector instance, you can map a scene like this:

mapPrototype { ChooseCampaign(get()) }

You have to put as many get() as parameters your ChooseCampaign constructor has.

In the case you are not using modules, the place to put the mapping is different, and you need to get the Injector instance.

In your suspend fun main() = Korge { block, you have the Stage singleton injected. This is the root view that has a reference to the Views singleton.

So there you can just access the injector like this: this.views.injector

You can then map your scenes whenever you like, though I suggest you do to it at the beginning of the application.

soywiz
  • 438
  • 3
  • 8