Error when setting Background

Asked

Viewed 121 times

4

When trying to change the background (image or color) the following error occurs. What can be?

MY XMLinserir a descrição da imagem aqui

ACTIVITY

07-22 20:29:52.223    4967-4967/? 
E/AndroidRuntime﹕ FATAL EXCEPTION: main
 java.lang.RuntimeException: Unable to start activity ComponentInfo{priscilla.com.br.nossahistoria/priscilla.com.br.nossahistoria.SplashCreen}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                at android.app.ActivityThread.access$600(ActivityThread.java:123)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:4424)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
                at android.view.LayoutInflater.createView(LayoutInflater.java:606)
                at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
                at android.app.Activity.setContentView(Activity.java:1835)
                at priscilla.com.br.nossahistoria.SplashCreen.onCreate(SplashCreen.java:15)
                at android.app.Activity.performCreate(Activity.java:4465)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                at android.app.ActivityThread.access$600(ActivityThread.java:123)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:4424)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.reflect.InvocationTargetException
                at java.lang.reflect.Constructor.constructNative(Native Method)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                at android.view.LayoutInflater.createView(LayoutInflater.java:586)
                at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
                at android.app.Activity.setContentView(Activity.java:1835)
                at priscilla.com.br.nossahistoria.SplashCreen.onCreate(SplashCreen.java:15)
                at android.app.Activity.performCreate(Activity.java:4465)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                at android.app.ActivityThread.access$600(ActivityThread.java:123)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:4424)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.OutOfMemoryError
                at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
                at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
                at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
                at android.content.res.Resources.loadDrawable(Resources.java:1935)
                at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                at android.view.View.<init>(View.java:2785)
                at android.view.ViewGroup.<init>(ViewGroup.java:385)
                at android.widget.LinearLayout.<init>(LinearLayout.java:174)
                at android.widget.LinearLayout.<init>(LinearLayout.java:170)
                at java.lang.reflect.Constructor.constructNative(Native Method)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                at android.view.LayoutInflater.createView(LayoutInflater.java:586)
                at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
                at android.app.Activity.setContentView(Activity.java:1835)
                at priscilla.com.br.nossahistoria.SplashCreen.onCreate(SplashCreen.java:15)
                at android.app.Activity.performCreate(Activity.java:4465)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                at android.app.ActivityThread.access$600(ActivityThread.java:123)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:4424)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke
  • Please edit your question with the code that generates this error or at least a fragment of it

  • Could you put the xml too? I believe the error is in it!

  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&#xA; xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"&#xA; android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=". Splashcreen" android:background="@drawable/splashcreen"> </Linearlayout>

  • package Priscilla.com.br.nossahistoria; import android.app.Activity; import android.os.Bundle; public class Splashcreen extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_creen); } }

  • @Priscillaandrademachado has the option to put the XML together with the question?

  • 1

    I just posted @Dener

  • In the class name, you didn’t mean "Splashscreen"?

  • but I already put ... this code is what was generated when we created the project

  • if I take the background image the program runs normally, if I do not shoot appears this error

  • Is giving OutOfMemoryError, my first guess would be that the image is too big for the device (or emulator) to support. What is the format (file extension) and its size (width and height) in pixels, to give a notion? A(s) folder(s) in which the drawable is (drawable-hdpi, drawable-xhdpi, etc.) and the device model can also help.

  • The image is in png and has 78.1 kb ... 2126 x 3544 pixels

  • I don’t know much about android, but maybe your error is related to this one: ONLY.

  • See the Thread that calls the splash

  • In the same directory as the drawable folder create a folder called drawable-nodpi and place the img inside that folder

Show 9 more comments

2 answers

0

Try using a smaller image for your layout or see if your application isn’t consuming too much device memory, thus leaving little room for image rendering.

0

The image is relatively large indeed. Different devices have different memory settings and a large image that is supported by one may not be supported by another. Resize the original image to smaller sizes and place each size in the folder res/drawable- appropriate (res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi, etc.), so each device will carry a figure of the appropriate size for its capacity. This question can help to calculate the appropriate sizes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.