Hi everyone, I started to learn Kotlin. I want to ...
# multiplatform
b
Hi everyone, I started to learn Kotlin. I want to show the json by making api call. However it does not read the instance of my class ShoppingListItem. Attached screenshot of entire code. I appreciate for any help.
l
Which source set is your model in and which is the main method in?
Typically, main lives in a specific source set, and models live in common (there can be exceptions, of course). If the source set main is in depends on common (it should), it will have access.
b
the model lives in common.
filestructure.png
l
If the model is in commonMain, other source sets should have access to it by default. Do you get an error when you try to compile? Some AS/IJ versions don’t handle source sets well.
b
I am just following the instructure of Kotlin Document. I really do not know where i am doing wrong
l
You don’t seem to have a kotlin folder below commonMain
commonMain/kotlin/ShoppingListItem.kt
b
111.png
It is still not working even though I created "kotlin" folder to put ShoppingListItem.kt in it.
l
Try a gradle sync? The folder should be highlighted blue.
b
i tried a gradls sync as well
Unresolved reference: ShoppingListItem
l
Also try renaming the file with a capital S. It’s showing the file symbol, not the class symbol (this shouldn’t affect much, but makes it easier to make sure it sees it right).
Try making a package for both files. I remember there being something about Java not being able to import things from the root package. Not sure if this carries over to Kotlin.
Make sure the folder structure matches the package name (commonMain/kotlin/com/example/shopping/ShoppingListItem.kt)
b
It was mentioning anything with package name in the documentation that what I am following
l
There’s a syntax error on line 8 of the ShoppingListItem file. The dash shouldn’t be there.
b
I deleted line 8
Server does not read the model
l
The fact that the IDE didn’t catch the syntax error tells me it doesn’t see the file as part of the project.
p
Judging by the screenshots is really hard to tell what is going on. If you can post a code, somewhere, it would be easier to catch the problem.