内存不足异常

时间:2012-11-19 11:21:18

标签: android

我时不时地得到这个例子,它让我很烦恼。在我的应用程序中,我们只是扫描一个条形码,它将数据从条形码发送到服务器。我已经尝试了很多东西来清理内存并避免内存泄漏但似乎没有任何工作。任何帮助都会得到满足。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.zxing.client.android/com.example.mypackage.filename}: android.view.InflateException: Binary XML file line #12: Error inflating class at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1652) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668) 
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2852) 
at android.app.ActivityThread.access$1600(ActivityThread.java:117) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:940) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:123) 
at android.app.ActivityThread.main(ActivityThread.java:3703) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class 
at android.view.LayoutInflater.createView(LayoutInflater.java:518) 
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212) 
at android.app.Activity.setContentView(Activity.java:1657) 
at com.example.mypackage.filename.onCreate(TaskSelector.java:164) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1616) 
... 12 more Caused by: java.lang.reflect.InvocationTargetException 
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:415) 
at android.view.LayoutInflater.createView(LayoutInflater.java:505) 
... 23 more Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget 
at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:477) 
at android.graphics.Bitmap.createBitmap(Bitmap.java:444) 
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349) 
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498) 
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473) 
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336) 
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) 
at android.content.res.Resources.loadDrawable(Resources.java:1709) 
at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 
at android.view.View.(View.java:1951) at android.view.View.(View.java:1899) 
at android.view.ViewGroup.(ViewGroup.java:286) at android.widget.RelativeLayout.(RelativeLayout.java:173) ... 26 more

2 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

使用此代码可能会有所帮助,或者让我知道我还有其他解决方案

答案 1 :(得分:0)

您的位图太大,或者您一次装载太多。