Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TornadoFx ClassCastException #1343

Open
resuwa opened this issue Oct 15, 2021 · 1 comment
Open

TornadoFx ClassCastException #1343

resuwa opened this issue Oct 15, 2021 · 1 comment

Comments

@resuwa
Copy link

resuwa commented Oct 15, 2021

As a beginner with Tornadofx and Kotlin I am learning with the nice examples from Edvin Syse.
Now I tried the Scopes example(Share view state using a custom scope in a TornadoFX Master/Detail app) and get the the error message "java.lang.ClassCastException: tornadofx.Scope cannot be cast to ...MyScope"
I am using Intelij IDEA/Gradle 5.3 /Kotlin 1.4.32/TornadoFx 1.7.14/JRE 1.8
Is it a version issue or do I miss something?

`class CustomerModel: ItemViewModel(){

val custName = bind {item?.custNameProperty }
val country = bind {item?.countryProperty }

}
class CustScope :Scope(){
val model= CustomerModel()
val customers = FXCollections.observableArrayList(Customer("a","Frankreich"),
Customer("b","Italien"))
}`

class CustEdit : View("My View") {

override val scope = super.scope as CustScope

val itemsGlobalObject = Locale.getISOCountries().map { Locale("", it) }.observable()
val itemsGlobal = itemsGlobalObject.mapEach { displayCountry }.sorted()

override val root = form {
    prefWidth=300.0
    hboxConstraints { hGrow =Priority.ALWAYS }
    fieldset{
        field("Kunde"){
           // textfield(model.custName)
            textfield(scope.model.custName)
        }
        field("Land"){
            combobox(scope.model.country, itemsGlobal) {
                prefWidth = 125.0
                makeAutocompletable()
            }
        }
    }
@SKeeneCode
Copy link

SKeeneCode commented Oct 25, 2021

I suspect when you're adding your CustEdit onto the scene graph you are not explicitly putting it into your custom scope.

Something like add(find(CustEdit::class, CustScope())) should work.

However you should not use scopes to hold anything. Create a ViewModal and inject that into your views and controllers:

private val myViewModal: MyViewModal by inject()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants