2014-07-07 4 views
-2

때때로 작동하지만 때로는 작동하지 않습니다.
누구든지 내가 문제를 찾아 내고 그에 대처하는 방법을 알려줄 수 있습니까? 고맙습니다!잡히지 않은 예외로 스레드가 종료 됨 android (OutOfMemory)

오류 로그 : 모든

07-07 04:07:48.583: W/dalvikvm(3030): threadid=1: thread exiting with uncaught exception (group=0xb3afeba8) 
07-07 04:07:48.603: E/AndroidRuntime(3030): FATAL EXCEPTION: main 
07-07 04:07:48.603: E/AndroidRuntime(3030): Process: com.example.kingdoms, PID: 3030 
07-07 04:07:48.603: E/AndroidRuntime(3030): java.lang.OutOfMemoryError 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.graphics.Bitmap.nativeCreate(Native Method) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.graphics.Bitmap.createBitmap(Bitmap.java:809) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.graphics.Bitmap.createBitmap(Bitmap.java:786) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.graphics.Bitmap.createBitmap(Bitmap.java:718) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:594) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at com.example.kingdoms.war1.onCreate(war1.java:1433) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.app.Activity.performCreate(Activity.java:5231) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.os.Handler.dispatchMessage(Handler.java:102) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.os.Looper.loop(Looper.java:136) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at android.app.ActivityThread.main(ActivityThread.java:5017) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at java.lang.reflect.Method.invoke(Method.java:515) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
07-07 04:07:48.603: E/AndroidRuntime(3030):  at dalvik.system.NativeStart.main(Native Method) 
07-07 04:12:48.683: I/Process(3030): Sending signal. PID: 3030 SIG: 9 
+0

코드는 어디에 있습니까? 디버깅 해봤습니까? 102 번 라인은 무엇입니까? 136 번 라인에는 무엇이 있습니까? 무엇을 했습니까? 이것은 문맥이없는 큰 오류 덤프 일뿐입니다! – RossC

답변

2

첫째, OOM 예외는 없습니다 처리 방지해야합니다.

보통 OOM 예외는 당신은 그들이 너무 큰 경우 메모리에로드하기 전에 당신의 bitmaps을 확장 할 수 OOM을 방지하기 때문에 crash.In 순서에 응용 프로그램을 일으키는 RAM이 많이 걸립니다 bitmaps에 발생합니다. BitmapFactory.Options을 사용하고 요구 사항에 따라 축소 할 수 있습니다.

public static Bitmap decodeSampledBitmapFromPath(String path, int reqWidth, 
       int reqHeight) { 

     final BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeFile(path, options); 

     options.inSampleSize = calculateInSampleSize(options, reqWidth, 
       reqHeight); 

     // Decode bitmap with inSampleSize set 
     options.inJustDecodeBounds = false; 
     Bitmap bmp = BitmapFactory.decodeFile(path, options); 
     return bmp; 
    } 

    public static int calculateInSampleSize(BitmapFactory.Options options, 
      int reqWidth, int reqHeight) { 

     final int height = options.outHeight; 
     final int width = options.outWidth; 
     int inSampleSize = 1; 

     if (height > reqHeight || width > reqWidth) { 
      if (width > height) { 
        inSampleSize = Math.round((float) height/(float) reqHeight); 
      } else { 
        inSampleSize = Math.round((float) width/(float) reqWidth); 
      } 
     } 
    return inSampleSize; 
    } 
+0

하나의 비트 맵을 몇 개의 비트 맵으로 나눌 수 있습니까? 크기는 작지만 비트 맵 수가 더 많습니다. – user3474778

+0

@ user3474778 왜 비트 맵을 나누고 싶습니까? 작은 크기의 비트 맵을 사용하거나 설명 된대로 크기를 조정하십시오. – CodeWarrior

+0

내 비트 맵을 화면에 맞추기 원하기 때문입니다. 다른 제안이 있으십니까? 고맙습니다. – user3474778

관련 문제