简体   繁体   中英

Expected resource of type integer with an image

I am working with Android Studio and Kotlin.

I am trying to use different images in my project (in drawable):

But when I am trying to use one in the DataSource file, it happens an error:


package com.example.affirmations.data

import com.example.affirmations.R
import com.example.affirmations.model.Affirmation


class DataSource {

    fun loadAffirmations():List<Affirmation>{
        return listOf<Affirmation>(
            Affirmation(R.string.affirmation1, R.drawable.image1),
//            Affirmation(string.affirmation2, R.drawable.image2),
//            Affirmation(string.affirmation3, R.drawable.image3),
//            Affirmation(string.affirmation4),
//            Affirmation(string.affirmation5),
//            Affirmation(string.affirmation6),
//            Affirmation(string.affirmation7),
//            Affirmation(string.affirmation8),
//            Affirmation(string.affirmation9),
//            Affirmation(string.affirmation10)
        )

    }
}


在此处输入图像描述

Thank you

Wherever you define Affirmation (you can hold Ctrl or whatever and click it to go there) it's expecting an Integer resource for the second parameter - it's probably annotated with @IntegerRes instead of @DrawableRes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM