My app is getting crashed when i click on RecyclerView item, The Error is occurring Because of Toast.make(), when i comment or remove the Toast in check(positon:Int) function then it doesn't crash. It is only crashing while Toast is there. I search a lot for a fix but i couldn't find one, please help to fix this error
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
Using Toast.makeText(this, position, Toast.LENGTH_SHORT).show() you are trying to use the method:
public static Toast makeText (Context context,
int resId,
int duration)
where the resId represents the resource id of the string resource to use (as R.string.xxxx).
Use position.toString() to convert the int into a String:
Toast.makeText(this, position.toString(), Toast.LENGTH_SHORT)
Toast.makeText(ProjectActivity.this, "Your message here", Toast.LENGTH_SHORT).show();
The second parameter is String but you are using Int here, convert your Int to String will make work done
ex:
`Toast.makeText(this, position.toString(), Toast.LENGTH_SHORT).show()`
Toast.makeText(this, ""+position, Toast.LENGTH_SHORT).show()
User contributions licensed under CC BY-SA 3.0