Android:奇怪的内存异常

时间:2010-09-02 22:34:12

标签: android out-of-memory

我有一个奇怪的内存不足异常的问题,只发生在某些设备上(主要是HTC Desire)。每次用户开始某项活动时都会发生这种情况(无论如何 - 有两条通往该活动的路径),我真的很困惑为什么(我检查了泄漏并且找不到任何活动)......

调用setContentView时或之后不久会抛出错误。

这是抛出错误的代码块:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(DebugFlags.LOG_MEMORY)
    {
        MemoryAnalyser.logHeap(this.getClass());
    }
    setContentView(R.layout.activity_stats);
    try
    {
    monthsAvailable = getMonthTimeStamps();
    Spinner xSpin = (Spinner) findViewById(R.id.spinnerTimespan);
    m_adapterForSpinner = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);       
    m_adapterForSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    xSpin.setAdapter(m_adapterForSpinner);
    for(Iterator<monthObject> i = monthsAvailable.iterator();i.hasNext();)
    {
        monthObject xObj = i.next();
        String dateString = String.format("%1$te.%1$tm.%1$tY - %2$te.%2$tm.%2$tY", xObj.fromDate, xObj.toDate);
        m_adapterForSpinner.add(dateString);
    }
    xSpin.setSelection(xSpin.getCount()-1);
    xSpin.setOnItemSelectedListener(this);
    //setupStatData(null, null);
    checkStatsAvailable();
    //throw(new java.lang.OutOfMemoryError());
    }
     catch(java.lang.OutOfMemoryError e)
     {
         MemoryAnalyser.dumpHeap();
         MemoryAnalyser.logHeap(this.getClass());
         Toast xToast = Toast.makeText(getApplicationContext(), "OutOfMemoryException - bitte Log und Datei com.eventkontor.networkcheck.hprof auf SD-Karte an Entwickler senden", 5000);
         xToast.show();
         this.finish();
     }
    if(DebugFlags.LOG_MEMORY)
    {
        MemoryAnalyser.logHeap(this.getClass());
    }
}
正如我所说的那样 - 调用setContentView或调用getMonthTimeStamps()

时通常会抛出错误

getMonthTimeStamps是一个辅助函数,它创建内部数据库中可用日期的列表。它创建了几个(小对象)并返回一个ArrayList。这是函数

private ArrayList<monthObject> getMonthTimeStamps()
{
    ArrayList<monthObject> dates = new ArrayList<monthObject>();
    Cursor c = getContentResolver().query(CallLogTableMetaData.CONTENT_URI, new String[]{CallLogTableMetaData.CALLOG_DATE}, null, null, CallLogTableMetaData._ID + " asc");
    try{

    if(c.moveToFirst())
    {
        SharedPreferences prefs = Utils.getPreferences(this);
        int resetDay = prefs.getInt("pref_callog_reset_day", 1);
        prefs = null;
        long starttime = c.getLong(0);
        c.close();
        c=null;
        Date startDate = new Date(starttime);
        GregorianCalendar today = new GregorianCalendar();
        GregorianCalendar xCal = new GregorianCalendar();
        xCal.setTime(startDate);
        xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay);
        while(xCal.before(today))
        {
            monthObject xObj = new monthObject();
            xObj.setTimestamp(xCal.getTimeInMillis());
            xObj.setFromDate(xCal.getTime());
            xCal.add(GregorianCalendar.MONTH, 1);
            xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay);
            xCal.set(Calendar.HOUR_OF_DAY, 0);
            xCal.set(Calendar.MINUTE, 0);
            xCal.set(Calendar.SECOND, 0);
            xCal.set(Calendar.MILLISECOND, 0);
            xObj.setToDate(xCal.getTime());
            xObj.setToTimestamp(xCal.getTimeInMillis());
            dates.add(xObj);
            xObj = null;
        }
        xCal = null;
        today = null;
        return dates;
    }
    else
    {
        return dates;
    }
    }
    finally{
        try
        {
            c.close();
        }
        catch(Exception e)
        {

        }
    }
    }

我并没有声称我的代码是完美无缺的,但我真的不明白为什么会抛出这个错误。 XML布局不包含对图像的任何引用,也不是非常复杂(textview,spinner,tablelayout)。

以下是我从一位用户收到的错误日志:

I/ActivityManager(16789): Starting activity: Intent { cmp=com.eventkontor.networkcheck/.StatActivity }
D/dalvikvm( 5053): GC freed 8267 objects / 556152 bytes in 45ms
D/dalvikvm( 5053): GC freed 1716 objects / 371240 bytes in 45ms
D/dalvikvm( 5053): GC freed 15 objects / 62936 bytes in 56ms
D/dalvikvm( 5053): GC freed 4 objects / 233856 bytes in 77ms
D/dalvikvm( 5053): GC freed 14 objects / 544 bytes in 83ms
W/ActivityManager(16789): Launch timeout has expired, giving up wake lock!
W/ActivityManager(16789): Activity idle timeout for HistoryRecord{46a4b878 com.eventkontor.networkcheck/.StatActivity}
D/dalvikvm( 5053): GC freed 3 objects / 210456 bytes in 107ms
D/dalvikvm( 5053): GC freed 3 objects / 315656 bytes in 118ms
D/dalvikvm( 5210): GC freed 7752 objects / 904320 bytes in 1116ms
D/dalvikvm( 5053): GC freed 2 objects / 48 bytes in 136ms
D/dalvikvm( 5053): GC freed 3 objects / 473448 bytes in 155ms
D/dalvikvm(  641): GC freed 4397 objects / 781024 bytes in 1246ms
D/dalvikvm( 5053): GC freed 2 objects / 48 bytes in 175ms
D/dalvikvm( 5053): GC freed 2 objects / 56 bytes in 203ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.522MB to 24.000MB
D/dalvikvm( 5053): GC freed 3 objects / 710120 bytes in 207ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 2 objects / 56 bytes in 220ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.012MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 16-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 238ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 24-byte allocation.
I/dalvikvm( 5053): "HeapWorker" daemon prio=5 tid=5 RUNNABLE
I/dalvikvm( 5053):   | group="system" sCount=0 dsCount=0 s=N obj=0x44e0eab8 self=0x14a298
I/dalvikvm( 5053):   | sysTid=5054 nice=0 sched=0/0 cgrp=default handle=1351480
I/dalvikvm( 5053):   at com.android.internal.os.BinderInternal$GcWatcher.finalize(BinderInternal.java:~48)
I/dalvikvm( 5053):   at dalvik.system.NativeStart.run(Native Method)
I/dalvikvm( 5053): 
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 291ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 40-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 40-byte allocation.
I/dalvikvm( 5053): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm( 5053):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b470 self=0xbdd0
I/dalvikvm( 5053):   | sysTid=5053 nice=0 sched=0/0 cgrp=default handle=-1343993180
I/dalvikvm( 5053):   at com.eventkontor.networkcheck.StatActivity.getMonthTimeStamps(StatActivity.java:~270)
I/dalvikvm( 5053):   at com.eventkontor.networkcheck.StatActivity.onCreate(StatActivity.java:119)
I/dalvikvm( 5053):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
I/dalvikvm( 5053):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
I/dalvikvm( 5053):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
I/dalvikvm( 5053):   at android.app.ActivityThread.access$2200(ActivityThread.java:126)
I/dalvikvm( 5053):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
I/dalvikvm( 5053):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm( 5053):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm( 5053):   at android.app.ActivityThread.main(ActivityThread.java:4595)
I/dalvikvm( 5053):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm( 5053):   at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm( 5053):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
I/dalvikvm( 5053):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I/dalvikvm( 5053):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm( 5053): 
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 231ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 24-byte allocation.
I/dalvikvm( 5053): "HeapWorker" daemon prio=5 tid=5 RUNNABLE
I/dalvikvm( 5053):   | group="system" sCount=0 dsCount=0 s=N obj=0x44e0eab8 self=0x14a298
I/dalvikvm( 5053):   | sysTid=5054 nice=0 sched=0/0 cgrp=default handle=1351480
I/dalvikvm( 5053):   at com.android.internal.os.BinderInternal$GcWatcher.finalize(BinderInternal.java:~48)
I/dalvikvm( 5053):   at dalvik.system.NativeStart.run(Native Method)
I/dalvikvm( 5053): 
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
I/dalvikvm( 5053): Uncaught exception thrown by finalizer (will be discarded):
I/dalvikvm( 5053): Ljava/lang/OutOfMemoryError;: [memory exhausted]
I/dalvikvm( 5053): at dalvik.system.NativeStart.main(Native Method)
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 237ms
I/dalvikvm-heap( 5053): Forcing collection of SoftReferences for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.012MB to 24.000MB
D/dalvikvm( 5053): GC freed 1 objects / 16 bytes in 220ms
E/dalvikvm-heap( 5053): Out of memory on a 24-byte allocation.
I/dalvikvm( 5053): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm( 5053):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b470 self=0xbdd0
I/dalvikvm( 5053):   | sysTid=5053 nice=0 sched=0/0 cgrp=default handle=-1343993180
I/dalvikvm( 5053):   at com.eventkontor.networkcheck.StatActivity.getMonthTimeStamps(StatActivity.java:~270)
I/dalvikvm( 5053):   at com.eventkontor.networkcheck.StatActivity.onCreate(StatActivity.java:119)
I/dalvikvm( 5053):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
I/dalvikvm( 5053):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
I/dalvikvm( 5053):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
I/dalvikvm( 5053):   at android.app.ActivityThread.access$2200(ActivityThread.java:126)
I/dalvikvm( 5053):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
I/dalvikvm( 5053):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm( 5053):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm( 5053):   at android.app.ActivityThread.main(ActivityThread.java:4595)
I/dalvikvm( 5053):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm( 5053):   at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm( 5053):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
I/dalvikvm( 5053):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I/dalvikvm( 5053):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm( 5053): 
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=22204KB, Bitmap Size=1806KB
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 11 objects / 728 bytes in 221ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 221ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 136-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 219ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 220ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 54-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 4 objects / 272 bytes in 221ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 24-byte allocation
I/dalvikvm-heap( 5053): Clamp target GC heap from 26.011MB to 24.000MB
D/dalvikvm( 5053): GC freed 0 objects / 0 bytes in 240ms
I/dalvikvm-heap( 5053): Clamp target GC heap from 24.011MB to 24.000MB
I/dalvikvm-heap( 5053): Grow heap (frag case) to 24.000MB for 68-byte allocation
D/dalvikvm( 5053): GC freed 589340 objects / 19930400 bytes in 180ms
I/dalvikvm( 5053): hprof: dumping VM heap to "/sdcard/com.eventkontor.networkcheck.hprof-hptemp".
I/dalvikvm( 5053): hprof: dumping heap strings to "/sdcard/com.eventkontor.networkcheck.hprof".
I/dalvikvm( 5053): hprof: heap dump completed, temp file removed
D/dalvikvm( 5053): GC freed 8 objects / 616 bytes in 1056ms
D/NetworkCheck( 5053): debug. =================================
D/NetworkCheck( 5053): debug.heap native: allocated 5,81MB of 6,94MB (0,61MB free) in [com.eventkontor.networkcheck.StatActivity]
D/NetworkCheck( 5053): debug.memory: allocated: 22,00MB of 24,00MB (19,00MB free)
D/dalvikvm( 5053): GC freed 148 objects / 7608 bytes in 34ms
D/dalvikvm( 5053): GC freed 5 objects / 264 bytes in 33ms
E/dalvikvm-heap( 5053): 32980-byte external allocation too large for this process.
E/dalvikvm( 5053): Out of memory: Heap Size=22791KB, Allocated=2743KB, Bitmap Size=1806KB
E/        ( 5053): VM won't let us allocate 32980 bytes
D/skia    ( 5053): --- decoder->decode returned false
D/AndroidRuntime( 5053): Shutting down VM
W/dalvikvm( 5053): threadid=3: thread exiting with uncaught exception (group=0x4001b390)
D/UNHANDLED_EXCEPTION( 5053): Writing unhandled exception to: /data/data/com.eventkontor.networkcheck/files/1.5-55980.stacktrace
I/global  ( 5053): Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
D/UNHANDLED_EXCEPTION( 5053): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eventkontor.networkcheck/com.eventkontor.networkcheck.StatActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class <unknown>
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
D/UNHANDLED_EXCEPTION( 5053): at android.os.Handler.dispatchMessage(Handler.java:99)
D/UNHANDLED_EXCEPTION( 5053): at android.os.Looper.loop(Looper.java:123)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.main(ActivityThread.java:4595)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Method.invokeNative(Native Method)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Method.invoke(Method.java:521)
D/UNHANDLED_EXCEPTION( 5053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
D/UNHANDLED_EXCEPTION( 5053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
D/UNHANDLED_EXCEPTION( 5053): at dalvik.system.NativeStart.main(Native Method)
D/UNHANDLED_EXCEPTION( 5053): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class <unknown>
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
D/UNHANDLED_EXCEPTION( 5053): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
D/UNHANDLED_EXCEPTION( 5053): at android.widget.Toast.makeText(Toast.java:235)
D/UNHANDLED_EXCEPTION( 5053): at com.eventkontor.networkcheck.StatActivity.onCreate(StatActivity.java:140)
D/UNHANDLED_EXCEPTION( 5053): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
D/UNHANDLED_EXCEPTION( 5053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
D/UNHANDLED_EXCEPTION( 5053): ... 11 more
D/UNHANDLED_EXCEPTION( 5053): Caused by: java.lang.reflect.InvocationTargetException
D/UNHANDLED_EXCEPTION( 5053): at android.widget.LinearLayout.<init>(LinearLayout.java:92)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Constructor.constructNative(Native Method)
D/UNHANDLED_EXCEPTION( 5053): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
D/UNHANDLED_EXCEPTION( 5053): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
D/UNHANDLED_EXCEPTION( 5053): ... 20 more
D/UNHANDLED_EXCEPTION( 5053): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
D/UNHANDLED_EXCEPTION( 5053): at android.content.res.Resources.loadDrawable(Resources.java:1705)
D/UNHANDLED_EXCEPTION( 5053): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
D/UNHANDLED_EXCEPTION( 5053): at android.view.View.<init>(View.java:1850)
D/UNHANDLED_EXCEPTION( 5053): at android.view.View.<init>(View.java:1799)
D/UNHANDLED_EXCEPTION( 5053): at android.view.ViewGroup.<init>(ViewGroup.java:296)
D/UNHANDLED_EXCEPTION( 5053): ... 24 more

由于

安德烈亚斯

3 个答案:

答案 0 :(得分:1)

由GregorianCalendar引起的无限循环没有递增日期。仍在调查这个问题,但这个问题已得到解决。

答案 1 :(得分:0)

只是阅读堆栈跟踪,你的问题似乎是你试图加载一些位图。这是一个根本原因你是否正在加载一堆图像?该异常可防止布局膨胀。您需要以太网缓存或缩小图像大小。 通过这些

查看和调试
D/UNHANDLED_EXCEPTION( 5053): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
D/UNHANDLED_EXCEPTION( 5053): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
D/UNHANDLED_EXCEPTION( 5053): at android.content.res.Resources.loadDrawable(Resources.java:1705)
D/UNHANDLED_EXCEPTION( 5053): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
D/UNHANDLED_EXCEPTION( 5053): at android.view.View.<init>(View.java:1850)
D/UNHANDLED_EXCEPTION( 5053): at android.view.View.<init>(View.java:1799)
D/UNHANDLED_EXCEPTION( 5053): at android.view.ViewGroup.<init>(ViewGroup.java:296)

答案 2 :(得分:0)

你看过相关的问题吗?这是一个相关的SO search。其中一些指向使用BitmapFactory类的answer。这种方法对每个图像进行下采样,以减少它们对内存的影响。希望它有所帮助。