Autore Topic: Randomicamente l\'Application instance si resetta dopo aver utilizzato la camera  (Letto 307 volte)

Offline Link_88

  • Nuovo arrivato
  • *
  • Post: 10
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Note II
  • Sistema operativo:
    Windows 7
Salve a tutti,
ho un'activity che mostra la preview della camera e permette l'acquisizione della foto e relativo salvataggio in base64 della foto sul sqlite.

In chiusura della relativa activity l'istanza di Application del progetto si "resetta" e i suoi campi associati diventano null.
Alla prima chiamata di una variabile a lei associata il sistema crasha per NullPointerException.

Questo problema si verifica randomicamente. La maggior parte delle volte il salvataggio funziona correttamente.

La chiamata dalla classe Application fatta da un SherlockListFragment che genera il crash è la seguente:

Codice (Java): [Seleziona]
@EApplication
public class SApplication extends Application {

    public static Abatis abatis;

    public static Abatis getAbatis() {
        return abatis;
    }
}

Questo lancia la seguente eccezzione:

Codice (Java): [Seleziona]
10-25 14:31:18.079: D/it.helian.segnalami.activity.ArchivioTabsActivity_(6529): REGISTER BROADCASTER
10-25 14:31:18.084: D/AndroidRuntime(6529): Shutting down VM
10-25 14:31:18.084: W/dalvikvm(6529): threadid=1: thread exiting with uncaught exception (group=0x41a222a0)
10-25 11:54:14.199: E/AndroidRuntime(23462): FATAL EXCEPTION: main
10-25 11:54:14.199: E/AndroidRuntime(23462): java.lang.RuntimeException: Unable to resume activity {it.helian.cittasicura/it.helian.segnalami.activity.ArchivioTabsActivity_}: java.lang.NullPointerException
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2616)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2644)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2130)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.os.Looper.loop(Looper.java:137)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.ActivityThread.main(ActivityThread.java:4898)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at java.lang.reflect.Method.invokeNative(Native Method)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at java.lang.reflect.Method.invoke(Method.java:511)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at dalvik.system.NativeStart.main(Native Method)
10-25 11:54:14.199: E/AndroidRuntime(23462): Caused by: java.lang.NullPointerException
10-25 11:54:14.199: E/AndroidRuntime(23462):    at it.helian.segnalami.activity.ArchivioActivity$LoaderListFragment.onResume(ArchivioActivity.java:426)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:918)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1065)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1854)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:431)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:420)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at com.actionbarsherlock.app.SherlockFragmentActivity.onPostResume(SherlockFragmentActivity.java:69)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.Activity.performResume(Activity.java:5293)
10-25 11:54:14.199: E/AndroidRuntime(23462):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2606)
10-25 11:54:14.199: E/AndroidRuntime(23462):    ... 12 more

Per quale motivo l'istanza di Application si resetta?

Grazie per le risposte
L.F.

Post unito: 29 Ottobre 2013, 12:37:38 CET
Ho trovato il punto di crash:

Codice (Java): [Seleziona]
[code=java]     // From the Camera.PictureCallback
        public void onPictureTaken(byte[] data, Camera camera) {
                byteArr = data;
                [b]lastBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);[/b]
                new CreateThumbnailTask(lastBitmap, 160, 120).execute();
                cameraView.startPreview();
        }
[/code]

BitmapFactory.decodeByteArray in particolari situazioni genera il seguente errore:

Codice (Java): [Seleziona]
[code=java]10-29 12:22:39.329: E/dalvikvm-heap(7935): Out of memory on a 1228816-byte allocation.
10-29 12:22:39.329: I/dalvikvm(7935): "main" prio=5 tid=1 RUNNABLE
10-29 12:22:39.329: I/dalvikvm(7935):   | group="main" sCount=0 dsCount=0 obj=0x40f5f508 self=0x40ea0a38
10-29 12:22:39.329: I/dalvikvm(7935):   | sysTid=7935 nice=0 sched=0/0 cgrp=apps handle=1074782000
10-29 12:22:39.329: I/dalvikvm(7935):   | schedstat=( 104469352040 13670620074 105100 ) utm=9912 stm=534 core=2
10-29 12:22:39.329: I/dalvikvm(7935):   at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
10-29 12:22:39.329: I/dalvikvm(7935):   at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:549)
10-29 12:22:39.329: I/dalvikvm(7935):   at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:567)
10-29 12:22:39.329: I/dalvikvm(7935):   at it.helian.customcamera.CameraActivity.onPictureTaken(CameraActivity.java:190)
10-29 12:22:39.329: I/dalvikvm(7935):   at android.hardware.Camera$EventHandler.handleMessage(Camera.java:776)
10-29 12:22:39.329: I/dalvikvm(7935):   at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 12:22:39.329: I/dalvikvm(7935):   at android.os.Looper.loop(Looper.java:137)
10-29 12:22:39.329: I/dalvikvm(7935):   at android.app.ActivityThread.main(ActivityThread.java:4898)
10-29 12:22:39.329: I/dalvikvm(7935):   at java.lang.reflect.Method.invokeNative(Native Method)
10-29 12:22:39.329: I/dalvikvm(7935):   at java.lang.reflect.Method.invoke(Method.java:511)
10-29 12:22:39.329: I/dalvikvm(7935):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-29 12:22:39.329: I/dalvikvm(7935):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-29 12:22:39.329: I/dalvikvm(7935):   at dalvik.system.NativeStart.main(Native Method)
10-29 12:22:39.329: D/skia(7935): --- decoder->decode returned false
10-29 12:22:45.494: D/AndroidRuntime(7935): Shutting down VM
10-29 12:22:45.494: W/dalvikvm(7935): threadid=1: thread exiting with uncaught exception (group=0x40f5e2a0)
10-29 12:22:45.524: E/AndroidRuntime(7935): FATAL EXCEPTION: main
10-29 12:22:45.524: E/AndroidRuntime(7935): java.lang.OutOfMemoryError
10-29 12:22:45.524: E/AndroidRuntime(7935):     at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:549)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:567)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at it.helian.customcamera.CameraActivity.onPictureTaken(CameraActivity.java:190)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at android.hardware.Camera$EventHandler.handleMessage(Camera.java:776)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at android.os.Looper.loop(Looper.java:137)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at android.app.ActivityThread.main(ActivityThread.java:4898)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at java.lang.reflect.Method.invokeNative(Native Method)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at java.lang.reflect.Method.invoke(Method.java:511)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-29 12:22:45.524: E/AndroidRuntime(7935):     at dalvik.system.NativeStart.main(Native Method)
10-29 12:23:49.914: I/Process(7935): Sending signal. PID: 7935 SIG: 9
[/code]
« Ultima modifica: 29 Ottobre 2013, 12:37:38 CET da Link_88, Reason: Merged DoublePost »