Reputation: 47
So i tried to copy an image downloaded from the internet to my android studio mainactivity xml file via copying the image and pasting it onto the drawable resource folder, But for some reason, I got an error of "Failed to instantiate one or more classes" This is the first time I'm getting this error as my previous images copied the exact same way had no errors except for other images such as this one. Does it have something to do with PNG or JPG format?I tried to resync the project with Gradle files but its still the same. What should I do to solve this exception? Thank You.
1) the process of copying and pasting image to drawable
2) The error itself after pasting the image
java.lang.NullPointerException
at android.content.res.Resources_Delegate.getValue(Resources_Delegate.java:788)
at android.content.res.Resources.getValue(Resources.java:1286)
at android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:236)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:199)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:66)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
at sun.reflect.GeneratedConstructorAccessor1111.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:475)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:250)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:213)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadClass(LayoutlibCallbackImpl.java:193)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:333)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:152)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:222)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:368)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:567)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:549)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:863)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:549)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$1(RenderTask.java:680)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Edit: Also, When i try to compile the code, my project would'nt start unless i delete the image file in my drawable folder due to this error : `Error:Execution failed for task ':app:mergeDebugResources'.
C:\Users\TP_baseline\AndroidStudioProjects\COMTProject(MeloWide)\app\src\main\res\drawable\icons8-Medal-80.png: Error: '-' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore`
Upvotes: 0
Views: 1326
Reputation: 191743
Your image has dashes in the name. icons8-Medal-80.png
Replace it with an underscore or remove it.
Only lowercase alphanumeric (plus underscores) resource names are allowed, as indicated in the error.
Upvotes: 3
Reputation: 224
The problem is arise in two condition 1)in android resource names must contain only lowercase a-z, 0-9, or underscore. 2)if your image is corrupted then provide this type of error.so check in your resource any image file is corrupted
Upvotes: 0