应用程序崩溃在TextView

时间:2016-06-23 07:33:43

标签: java android

我试图在一个TextView中显示4个长文本(每个大约250个字符),这些文本由android上的几个图像分隔。这是一个片段,放在Host活动的scrollView中,使其可以滚动。

但它会抛出

  

java.lang.OutOfMemoryError

我很惊讶地发现应用程序内存不足,因为它唯一需要做的就是显示250个字符并对其应用自动换行。所以在谷歌搜索之后我将android:largeHeap设置为true以查看会发生什么。应用程序确实加载了文本但它使用了大量的CPU资源并使UI进入了蜗牛阶段。

所以我想知道:我在这里做错了什么?

感谢阅读。

这是完整的崩溃:

  

java.lang.OutOfMemoryError:无法分配69120012字节   分配8388608空闲字节和10MB直到OOM                                                                                at dalvik.system.VMRuntime.newNonMovableArray(Native Method)                                                                                在android.graphics.BitmapFactory.nativeDecodeAsset(本机方法)                                                                                在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)                                                                                在   android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)                                                                                在   android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)                                                                                在   android.content.res.Resources.loadDrawableForCookie(Resources.java:2730)                                                                                在android.content.res.Resources.loadDrawable(Resources.java:2635)                                                                                在android.content.res.TypedArray.getDrawable(TypedArray.java:870)                                                                                在android.widget.ImageView。(ImageView.java:152)                                                                                在android.widget.ImageView。(ImageView.java:140)                                                                                在   android.support.v7.widget.AppCompatImageView。(AppCompatImageView.java:57)                                                                                在   android.support.v7.widget.AppCompatImageView。(AppCompatImageView.java:53)                                                                                在   android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)                                                                                在   android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)                                                                                在   android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)                                                                                在   android.support.v4.view.LayoutInflaterCompatHC $ FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)                                                                                在   android.view.LayoutInflater $ FactoryMerger.onCreateView(LayoutInflater.java:189)                                                                                在   android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)                                                                                在   android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)                                                                                在android.view.LayoutInflater.rInflate(LayoutInflater.java:835)                                                                                在   android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)                                                                                在android.view.LayoutInflater.inflate(LayoutInflater.java:515)                                                                                在android.view.LayoutInflater.inflate(LayoutInflater.java:423)                                                                                在   nl.evhb.evhbmijnopbrengst.FragmentCoTwoInformation.onCreateView(FragmentCoTwoInformation.java:25)                                                                                在   android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)                                                                                在   android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)                                                                                在   android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)                                                                                在   android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)                                                                                在   android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)                                                                                在   android.support.v4.app.FragmentManagerImpl $ 1.run(FragmentManager.java:517)                                                                                在android.os.Handler.handleCallback(Handler.java:739)                                                                                在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                在android.os.Looper.loop(Looper.java:148)                                                                                在android.app.ActivityThread.main(ActivityThread.java:5461)                                                                                at java.lang.reflect.Method.invoke(Native Method)                                                                                在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

2 个答案:

答案 0 :(得分:1)

我很抱歉,但在再次查看日志之后,我意识到我以完整的1080p分辨率导入图像,这对于android.graphics.BitmapFactory进行处理太多了,这就是内存不足的原因。

我将图像设置为适合移动设备的尺寸,并且工作正常。

答案 1 :(得分:0)

当由于内存空间不足而无法分配对象时,Java虚拟机(JVM)会抛出OutOfMemoryError enter code here错误,垃圾收集器也无法释放一些空间。 试试吧......

  <application
.......................
............
         android:largeHeap="true"
        >