当前位置 : 主页 > 手机开发 > android >

android – 异常:OutOfMemoryError

来源:互联网 收集:自由互联 发布时间:2021-06-11
我在Play商店发布了我的应用程序.现在在Crashes和ANR中,我在2个设备上遇到错误(Galaxy Note3和Galaxy Note II).我不知道如何解决这些错误,这是什么类型的错误?所以请帮我解决这些错误.在其他
我在Play商店发布了我的应用程序.现在在Crashes和ANR中,我在2个设备上遇到错误(Galaxy Note3和Galaxy Note II).我不知道如何解决这些错误,这是什么类型的错误?所以请帮我解决这些错误.在其他设备上,我没有收到任何报告.

错误 –

java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
at android.content.res.Resources.loadDrawable(Resources.java:3022)
at android.content.res.Resources.getDrawable(Resources.java:1586)
at android.view.View.setBackgroundResource(View.java:16120)
at com.info.laughingbuddha.Buddha4.onCreateView(Buddha4.java:21)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:572)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1259)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
at dalvik.system.NativeStart.main(Native Method)

Buddha4.java-

package com.info.laughingbuddha;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class Buddha4 extends Fragment{

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.buddha, container, false);
    TextViewEx t = (TextViewEx) rootView.findViewById(R.id.textView2);
    t.setText("The Standing Happy Buddha brings riches and happiness.",true);
    t.setMovementMethod(new ScrollingMovementMethod());
    ImageView iv = (ImageView) rootView.findViewById(R.id.image1);
    iv.setBackgroundResource(R.drawable.buddha4);
    return rootView;
    }
}

我不知道我需要发布什么代码所以如果有人需要任何与此相关的代码请评论.谢谢.

尝试使用以下代码行创建缩放位图:

Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, width,
                height, true);

检查以下链接:

android – out of memory exception when creating bitmap

Android out of memory exception with bitmaps

Can I catch out of memory exception in Android in Bitmap allocation for decoding a picture file?

网友评论