简体   繁体   中英

How to get rid of the resource not found exception when clicked on item view on recycler view and instead of data and activity lauch, it crashes app

I have built an app to learn the use of adapter and recycler view. It contains a recycler view and adapter, it uses data class to show data on clicked to an item of the recycler view, but the app crashes on runtime whenever I click on an item of the recycler view and showing java resources not found exception , could any one please help me out from this because I am a newbie to learning and debugging this

2022-07-24 16:00:14.903 11460-11460/com.example.planetapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.planetapp, PID: 11460
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.planetapp/com.example.planetapp.PlanetDetail}: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
        at android.os.Handler.dispatchMessage(Handler.java:112)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:292)
        at android.content.res.Resources.getValue(Resources.java:1540)
        at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded(ResourceManagerInternal.java:180)
        at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:145)
        at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:136)
        at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:66)
        at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:91)
        at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:102)
        at com.example.planetapp.PlanetDetail.setData(PlanetDetail.kt:37)
        at com.example.planetapp.PlanetDetail.onCreate(PlanetDetail.kt:20)
        at android.app.Activity.performCreate(Activity.java:7458)
        at android.app.Activity.performCreate(Activity.java:7448)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3409)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199) 
        at android.os.Handler.dispatchMessage(Handler.java:112) 
        at android.os.Looper.loop(Looper.java:216) 
        at android.app.ActivityThread.main(ActivityThread.java:7625) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)```
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.planetapp/com.example.planetapp.PlanetDetail}: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff

The error above tells you what is really happening.

You are trying to access a "resource" using findViewById(int id) when it's not existing at all.

I recommend double-checking your code that uses findViewById(...) especially the code that intercepts the onClick(View view) event.

For example if you have an xml element with an ID like this:

<... android:id="@+id/MY_EXCELLENT_ID" ... />

You might've typed it like this:

findViewById(R.id.MY_EXCELLEND_ID);

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