android - 资源$NotFoundException : String resource ID #0x0 with Toast. makeText

标签 android android-studio kotlin android-toast

当我单击 RecyclerView 项目时,我的应用程序崩溃了,错误发生是因为 Toast.make() , 当我评论或删除 Toastcheck(positon:Int)功能然后它不会崩溃。它只是在 Toast 时崩溃有没有。我搜索了很多修复程序,但找不到,请帮助修复此错误

fun check(position: Int)
{
   Log.i("Check", position.toString())
   //if i remove the comment the app will crash
   //Toast.makeText(this, position, Toast.LENGTH_SHORT).show()
}

Error:

W/ResourceType: No package identifier when getting value for resource number 0x00000000
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.firebase_image_upload, PID: 27287
    android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.content.res.Resources.getText(Resources.java:331)
        at android.widget.Toast.makeText(Toast.java:287)
        at com.example.firebase_image_upload.ImagesActivity$check$1.run(ImagesActivity.kt:63)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

最佳答案

android.content.res.Resources$NotFoundException: String resource ID #0x0

使用 Toast.makeText(this, position, Toast.LENGTH_SHORT).show() 您正在尝试使用 the method :

public static Toast makeText (Context context, 
                int resId, 
                int duration)

其中 resId 表示要使用的字符串资源的资源 ID(如 R.string.xxxx)

使用 position.toString() 将 int 转换为 String:

Toast.makeText(this, position.toString(), Toast.LENGTH_SHORT)

关于android - 资源$NotFoundException : String resource ID #0x0 with Toast. makeText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58104225/

相关文章:

java - 如何以编程方式将 View 约束到 ConstraintLayout 中的父 View

java - 如何在自定义启动器上安装图标包?

android - Android 中所有包都无法下载错误

java - 无法编辑外部库文件 - 在 Android Studio 中显示为锁定

maven - Kotlin 编译为 java 1.8

kotlin - 如何在 ktor 中创建可重用的拦截器?

android - 哪个更快?来自 xml 或代码的布局

java - 如何连续动画 Fab 按钮(放大/缩小)?

java - 未找到 Gradle 方法 :'compile' 可能原因 : The Project

IntelliJ 中的 Kotlin 多平台 JVM 类型不匹配