2017-04-04 49 views
-2

我在項目中遇到了這個問題。我搜索堆棧溢出的答案,其中一些人給出瞭解決方案,這個問題"android:largeHeap="true",android:hardwareAccelerated="false",我在我的清單文件中嘗試了這兩行,但即使我得到了同樣的問題。無法分配12845068字節分配,11873648空閒字節和11MB直到OOM

但這裏有一件事我要說的問題在的Nexus 6只籌集到...剩下的設備Nexus 5的其運行正常

com.example.sit.mobileappmaker E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.sit.mobileappmaker, PID: 20509 java.lang.OutOfMemoryError: Failed to allocate a 12845068 byte allocation with 11873648 free bytes and 11MB until OOM 
    at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) 
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) 
    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080) 
    at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635) 
    at android.content.res.Resources.loadDrawable(Resources.java:2540) 
    at android.content.res.TypedArray.getDrawable(TypedArray.java:870) 
    at android.view.View.<init>(View.java:3954) 
    at android.widget.ImageView.<init>(ImageView.java:145) 
    at android.widget.ImageButton.<init>(ImageButton.java:84) 
    at android.widget.ImageButton.<init>(ImageButton.java:80) 
    at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:60) 
    at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:56) 
    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:118) 
    at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1021) 
    at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1080) 
    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at com.sit.mobileappmaker.MobileAppMaker.Templetes.ClassicMenu.onCreate(ClassicMenu.java:118) 
    at android.app.Activity.performCreate(Activity.java:6251) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
+1

看起來像您的圖片太大。圖像的分辨率是多少? –

回答

0

您的圖片過大,無法加載。 試試這個:

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inSampleSize = 2;//SCALE SIZE 
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, options); 

不要設置你的繪製在佈局XML。

相關問題