Answer the question
In order to leave comments, you need to log in
How to import custom class in kotlin?
there is a Drink class
package com.example.starbuuz
class Drink(name:String, description:String, imageResourceId: Int) {
private var name:String = name
private var description:String = description
private var imageResourceId: Int = imageResourceId
public var drinks:Array<Drink> = arrayOf(
Drink("Latte", "A coupleof espresso shots with steamed milk", R.drawable.latte),
Drink("Cappuccino", "Espresso, hot milk, and a steamed milk foam", R.drawable.cappuccino),
Drink("Filter","Heighest quality beans roasted and brewed fresh",R.drawable.filter)
)
public val getName:String
get() = name
public val getDescription:String
get() = description
public val getImageResourceId:Int
get() = imageResourceId
}
package com.example.starbuuz
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import com.example.starbuuz.Drink
class DrinkCategoryActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_drink_category)
val listArrayAdapter: ArrayAdapter<Drink> = ArrayAdapter<Drink>(this,
android.R.layout.simple_list_item_1,
Drink.drinks
)
}
}
Answer the question
In order to leave comments, you need to log in
At the very least, you don't have an instance of the Drink class, you're trying to work with the drinks field, as you would with a static field in Java. There are no statics in Kotlin. Details for example here: https://habr.com/ru/company/funcorp/blog/430836/
And yet, it seems to me that this code will gobble up all the memory and freeze. Because when the first Drink is created, Drink objects will start to be created recursively. Because when each one is created, three more are created, each of which will create three, and so on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question