图片无法在gridview中加载

时间:2019-01-04 10:47:33

标签: android uiimageview

我无法将imageview加载到网格视图 所有代码都是正确的,但我无法加载更多5张图片

在添加新图片时错误提示我

  

E / Android运行时:致命异常:主要       流程:com.children_activities,PID:8331       java.lang.RuntimeException:无法启动活动ComponentInfo {com.children_activities / com.children_activities.Image_show}:   android.view.InflateException:二进制XML文件第2行:二进制XML   文件行#2:错误夸大类           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)           在android.app.ActivityThread.-wrap14(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1631)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:154)           在android.app.ActivityThread.main(ActivityThread.java:6682)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1520)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)        原因:android.view.InflateException:二进制XML文件第2行:二进制XML文件第2行:膨胀类错误        原因:android.view.InflateException:二进制XML文件第2行:膨胀类错误        造成原因:java.lang.reflect.InvocationTargetException           在java.lang.reflect.Constructor.newInstance0(本地方法)           在java.lang.reflect.Constructor.newInstance(Constructor.java:430)           在android.view.LayoutInflater.createView(LayoutInflater.java:652)           在com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)           在android.view.LayoutInflater.onCreateView(LayoutInflater.java:724)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:792)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)           在android.view.LayoutInflater.inflate(LayoutInflater.java:496)           在android.view.LayoutInflater.inflate(LayoutInflater.java:427)           在android.view.LayoutInflater.inflate(LayoutInflater.java:378)           在android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)           在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)           在com.children_activities.Image_show.onCreate(Image_show.java:15)           在android.app.Activity.performCreate(Activity.java:6942)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)           在android.app.ActivityThread.-wrap14(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1631)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:154)           在android.app.ActivityThread.main(ActivityThread.java:6682)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1520)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)        由以下原因引起:java.lang.OutOfMemoryError:无法分配24471564字节分配以及16772768可用字节和21MB,直到OOM           在dalvik.system.VMRuntime.newNonMovableArray(本机方法)           在android.graphics.BitmapFactory.nativeDecodeAsset(本地方法)           在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:700)           在android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:535)           在android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1179)           在android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:770)           在android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621)           在android.content.res.Resources.loadDrawable(Resources.java:1727)           在android.content.res.TypedArray.getDrawable(TypedArray.java:945)           在android.view.View。(View.java:4516)           在android.view.ViewGroup。(ViewGroup.java:579)           在android.widget.RelativeLayout。(RelativeLayout.java:248)           在android.widget.RelativeLayout。(RelativeLayout.java:244)           在android.widget.RelativeLayout。(RelativeLayout.java:240)             ...另外25个

2 个答案:

答案 0 :(得分:0)

如果您检查 package pkg; localparam l = 1; typedef struct packed { bit [l-1:0] b; } s_t; endpackage interface i #(parameter p = pkg::l); pkg::s_t s; endinterface module m #(parameter p = pkg::l) ( pkg::s_t s ); i i0 (); endmodule 行,则看起来根本原因是Caused by:

通常可以通过为应用程序分配更多的堆空间来处理大型图像来解决此问题。
这可以通过将以下代码行添加到清单文件中来完成:

OutOfMemoryError: Failed to allocate a 24471564 byte allocation with 16772768 free bytes

答案 1 :(得分:0)

您正在使用非常大的图片。您需要在加载前压缩图像。 如果您直接设置图像来查看,请使用不同屏幕尺寸的图像。 请使用 Picasso 或 Glide 图片加载库。