Android Studio:应用程序在启动

时间:2017-05-15 01:18:29

标签: android android-studio android-fragments

发生在我身上的事情很奇怪。我最后一次通过Android Studio运行我的应用程序时工作正常。然后第二次,即使我没有改变任何东西,它也会在打开时崩溃。这是logcat:

  

05-14 20:13:45.718 25075-25082 /? E / art:向调试器发送回复失败:管道损坏   05-14 20:13:46.644 25075-25075 /? E / AndroidRuntime:致命异常:主要                                                      处理:com.breunig.nathan.progressbarderby,PID:25075                                                      java.lang.RuntimeException:Canvas:尝试绘制太大(118692000bytes)的位图。                                                          在android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)                                                          在android.graphics.Canvas.drawBitmap(Canvas.java:1415)                                                          在android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:528)                                                          在android.widget.ImageView.onDraw(ImageView.java:1316)                                                          在android.view.View.draw(View.java:17185)                                                          在android.view.View.updateDisplayListIfDirty(View.java:16167)                                                          在android.view.View.draw(View.java:16951)                                                          在android.view.ViewGroup.drawChild(ViewGroup.java:3727)                                                          在android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1230)                                                          在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)                                                          在android.view.View.draw(View.java:17188)                                                          在android.view.View.updateDisplayListIfDirty(View.java:16167)                                                          在android.view.View.draw(View.java:16951)                                                          在android.view.ViewGroup.drawChild(ViewGroup.java:3727)                                                          在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)                                                          在android.view.View.updateDisplayListIfDirty(View.java:16162)                                                          在android.view.View.draw(View.java:16951)                                                          在android.view.ViewGroup.drawChild(ViewGroup.java:3727)                                                          在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)                                                          在android.view.View.updateDisplayListIfDirty(View.java:16162)                                                          在android.view.View.draw(View.java:16951)                                                          在android.view.ViewGroup.drawChild(ViewGroup.java:3727)                                                          在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)                                                          在android.view.View.updateDisplayListIfDirty(View.java:16162)                                                          在android.view.View.draw(View.java:16951)                                                          在android.view.ViewGroup.drawChild(ViewGroup.java:3727)                                                          在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)                                                          在android.view.View.updateDisplayListIfDirty(View.java:16162)                                                          在android.view.View.draw(View.java:16951)                                                          在android.view.ViewGroup.drawChild(ViewGroup.java:3727)                                                          在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)                                                          在android.view.View.draw(View.java:17188)                                                          在com.android.internal.policy.DecorView.draw(DecorView.java:754)                                                          在android.view.View.updateDisplayListIfDirty(View.java:16167)                                                          在android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:648)                                                          在android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:654)                                                          在android.view.ThreadedRenderer.draw(ThreadedRenderer.java:762)                                                          在android.view.ViewRootImpl.draw(ViewRootImpl.java:2800)                                                          在android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2608)                                                          在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2215)                                                          在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)                                                          在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6338)                                                          在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:874)                                                          在android.view.Choreographer.doCallbacks(Choreographer.java:686)                                                          在android.view.Choreographer.doFrame(Choreographer.java:621)                                                          在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:860)                                                          在android.os.Handler.handleCallback(Handler.java:751)                                                          在android.os.Handler.dispatchMessage(Handler.java:95)                                                          在android.os.Looper.loop(Looper.java:154)                                                          在android.app.ActivityThread.main(ActivityThread.java:6121)                                                          at java.lang.reflect.Method.invoke(Native Method)                                                          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:889)                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

没有任何意义。我试过清理和重建项目没有运气。任何帮助,将不胜感激。感谢。

2 个答案:

答案 0 :(得分:2)

看起来你正在使用一个非常大的位图,画布无法处理它。也许您可以更改要显示的图像资源。

答案 1 :(得分:0)

  

Java.lang.RuntimeException:Canvas:   试图绘制太大(118692000bytes)bitmap

您正试图在Bitmap上绘制一个非常大的around 118MBCanvas)。要解决此错误,请尝试缩小bitmap的大小并在canvas上绘制。

您还可以使用Bitmap decoding方法:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;

请参阅有关Loading Large Bitmaps Efficiently

的文档

希望这会有所帮助〜