2016-11-11 1 views
-1

실제 장치에서 코드를 실행하려고하면 오류가 발생하지만 에뮬레이터에서 작동합니다. 오류가 패키지와 관련 있다고 생각합니다.표면보기 팽창 오류

다음은 오류입니다. 여기

11-11 18:27:57.481 30000-30000/com.lag.duckdodger.duckdodger E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: com.lag.duckdodger.duckdodger, PID: 30000 
                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lag.duckdodger.duckdodger/com.lag.duckdodger.duckdodger.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.lag.duckdodger.duckdodger.View.AnimationView 
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) 
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                       at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:154) 
                       at android.app.ActivityThread.main(ActivityThread.java:6077) 
                       at java.lang.reflect.Method.invoke(Native Method) 
                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                      Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.lag.duckdodger.duckdodger.View.AnimationView 
                      Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.lag.duckdodger.duckdodger.View.AnimationView 
                      Caused by: java.lang.reflect.InvocationTargetException 
                       at java.lang.reflect.Constructor.newInstance0(Native Method) 
                       at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
                       at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                       at com.lag.duckdodger.duckdodger.MainActivity.onCreate(MainActivity.java:12) 
                       at android.app.Activity.performCreate(Activity.java:6664) 
                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                       at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:154) 
                       at android.app.ActivityThread.main(ActivityThread.java:6077) 
                       at java.lang.reflect.Method.invoke(Native Method) 
                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
                      Caused by: java.lang.OutOfMemoryError: Failed to allocate a 103219212 byte allocation with 12866376 free bytes and 12MB until OOM 
                       at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
                       at android.graphics.Bitmap.nativeCreate(Native Method) 
                       at android.graphics.Bitmap.createBitmap(Bitmap.java:879) 
                       at android.graphics.Bitmap.createBitmap(Bitmap.java:856) 
                       at android.graphics.Bitmap.createBitmap(Bitmap.java:787) 
                       at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:663) 
                       at com.lag.duckdodger.duckdodger.AnimationModel.Background.<init>(Background.java:44) 
                       at com.lag.duckdodger.duckdodger.View.AnimationView.<init>(AnimationView.java:32) 
                       at java.lang.reflect.Constructor.newInstance0(Native Method)  
                       at java.lang.reflect.Constructor.newInstance(Constructor.java:430)  
                       at android.view.LayoutInflater.createView(LayoutInflater.java:645)  
                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)  
                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)  
                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)  
                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:518)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:426)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)  
                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)  
                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)  
                       at com.lag.duckdodger.duckdodger.MainActivity.onCreate(MainActivity.java:12)  
                       at android.app.Activity.performCreate(Activity.java:6664)  
                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)  
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)  
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)  
                       at android.app.ActivityThread.-wrap12(ActivityThread.java)  
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)  
                       at android.os.Handler.dispatchMessage(Handler.java:102)  
                       at android.os.Looper.loop(Looper.java:154)  
                       at android.app.ActivityThread.main(ActivityThread.java:6077)  
                       at java.lang.reflect.Method.invoke(Native Method)  
                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)  
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)  

는 패키지 스크린이다 : 여기 Package Screenshot

표면도이다;

package com.lag.duckdodger.duckdodger.View; 

import android.content.Context; 
import android.graphics.Canvas; 
import android.util.AttributeSet; 
import android.view.SurfaceHolder; 
import android.view.SurfaceView; 

import com.lag.duckdodger.duckdodger.AnimationModel.Background; 
import com.lag.duckdodger.duckdodger.AnimationModel.LogModel; 
import com.lag.duckdodger.duckdodger.AnimationModel.LogModel2; 
import com.lag.duckdodger.duckdodger.AnimationModel.PlayerModel; 
import com.lag.duckdodger.duckdodger.AnimationModel.RockModel; 

/** 
* Created by FrancisJan on 20/10/2016. 
*/ 

public class AnimationView extends SurfaceView implements SurfaceHolder.Callback{ 

    private final AnimationThread DuckThread; 
    private final Background bg; 
    private final PlayerModel pm; 
    private final LogModel lm; 
    private final RockModel rm; 
    private final LogModel2 lm2; 

    public AnimationView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     getHolder().addCallback(this); 
     DuckThread = new AnimationThread(this); 
     bg = new Background(context); 
     pm = new PlayerModel(context); 
     lm = new LogModel(context); 
     rm = new RockModel(context); 
     lm2 = new LogModel2(context); 
    } 

다음은 레이아웃 xml 파일입니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    tools:context="com.lag.duckdodger.duckdodger.MainActivity"> 

    <view 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.lag.duckdodger.duckdodger.View.AnimationView" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/view" /> 

</RelativeLayout> 

답변

1
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 103219212 byte allocation with 12866376 free bytes and 12MB until OOM 
      at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
      at android.graphics.Bitmap.nativeCreate(Native Method) 
      at android.graphics.Bitmap.createBitmap(Bitmap.java:879) 
      at android.graphics.Bitmap.createBitmap(Bitmap.java:856) 
      at android.graphics.Bitmap.createBitmap(Bitmap.java:787) 
      at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:663) 
      at com.lag.duckdodger.duckdodger.AnimationModel.Background.<init>(Background.java:44) 
      at com.lag.duckdodger.duckdodger.View.AnimationView.<init>(AnimationView.java:32) 

기본적 AnimationView 생성자는 Background 객체를 생성한다. Background의 생성자가 103MB 크기의 비트 맵을 만들려고합니다. 너무 큽니다. (크기가 5000x5000 픽셀 이미지와 비슷한 정도) Background 코드를 표시하지 않았지만 비트 맵을 만들거나 너무 큰 이미지를로드하려고합니다.

원본 비트 맵 리소스를보다 관리하기 쉬운 크기로 조정 해보십시오.