在三星设备上启动应用程序时,它崩溃并显示以下错误

时间:2018-09-21 07:59:56

标签: android bitmap imageview

每次在三星s7上启动应用程序时,我的应用程序就会崩溃。在其他设备上,我每次都可以正常工作。它告诉我,位图很大:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.slartibartfast.kslordered, PID: 4800
              java.lang.RuntimeException: Canvas: trying to draw too large(106616832bytes) bitmap.
                  at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)
                  at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)
                  at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:529)
                  at android.widget.ImageView.onDraw(ImageView.java:1367)
                  at android.view.View.draw(View.java:20370)
                  at android.view.View.updateDisplayListIfDirty(View.java:19315)
                  at android.view.View.draw(View.java:20093)
                  at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
                  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
                  at android.support.constraint.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1966)
                  at android.view.View.draw(View.java:20373)
                  at android.view.View.updateDisplayListIfDirty(View.java:19315)
                  at android.view.View.draw(View.java:20093)
                  at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
                  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
                  at android.view.View.updateDisplayListIfDirty(View.java:19306)
                  at android.view.View.draw(View.java:20093)
                  at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
                  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
                  at android.view.View.updateDisplayListIfDirty(View.java:19306)
                  at android.view.View.draw(View.java:20093)
                  at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
                  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
                  at android.view.View.updateDisplayListIfDirty(View.java:19306)
                  at android.view.View.draw(View.java:20093)
                  at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
                  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
                  at android.view.View.updateDisplayListIfDirty(View.java:19306)
                  at android.view.View.draw(View.java:20093)
                  at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
                  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
                  at android.view.View.draw(View.java:20373)
                  at com.android.internal.policy.DecorView.draw(DecorView.java:980)
                  at android.view.View.updateDisplayListIfDirty(View.java:19315)
                  at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:686)
                  at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:692)
                  at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:800)
                  at android.view.ViewRootImpl.draw(ViewRootImpl.java:3496)
                  at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3283)
                  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2818)
                  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1780)
                  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7827)
                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                  at android.view.Choreographer.doCallbacks(Choreographer.java:723)
                  at android.view.Choreographer.doFrame(Choreographer.java:658)
                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                  at android.os.Handler.handleCallback(Handler.java:789)
                  at android.os.Handler.dispatchMessage(Handler.java:98)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6944)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

我正在使用图像在imageView中显示。 你可以帮帮我吗? 你能帮我吗?

2 个答案:

答案 0 :(得分:0)

通常在Image恰好是日志所说的情况时发生。它太大了。我要做的是设置图像的所有变体,即hdpi,mdpi,xhdpi,xxhdpi and xxxhdpi。因此,在添加图像文件时,请确保每个文件都有一个,以便在那里的每个设备都能为其选择最佳的密度。

您的图像文件夹应如下图所示

image

答案 1 :(得分:0)

您测试的samsung s7的分辨率可能低于其他设备。

我建议您压缩此图像, 106616832bytes 肯定太大。