creswick / StreamingQR

Apache License 2.0
2 stars 0 forks source link

Creating Toast after application pauses causes NPE. #82

Closed lcasburn closed 10 years ago

lcasburn commented 10 years ago

This shows the logging output and stacktrace from error.

07-11 15:39:43.005  13793-13793/com.galois.qrstream E/qrstream﹕ onPause with Thread #1
07-11 15:39:43.010  13793-13793/com.galois.qrstream E/qrstream﹕ surfaceDestroyed
07-11 15:39:43.220  13793-13793/com.galois.qrstream W/SurfaceView﹕ CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false
07-11 15:39:43.355  13793-13793/com.galois.qrstream E/qrstream﹕ ReceiveFragment onStop
07-11 15:39:43.460  13793-13793/com.galois.qrstream D/qrstream﹕ DisplayUpdate.handleMessage, draw_qr_points
07-11 15:39:43.460  13793-13793/com.galois.qrstream D/qrstream﹕ draw_qr_points: pts length=48
07-11 15:39:43.460  13793-22989/com.galois.qrstream D/qrlib﹕ 2014-07-11 15:39:43.464 org.slf4j.impl.AndroidLoggerAdapter.log(AndroidLoggerAdapter.java:55)
    QRLib: Already saved chunk 1 of 143
07-11 15:39:43.460  13793-22989/com.galois.qrstream D/qrlib﹕ 2014-07-11 15:39:43.465 org.slf4j.impl.AndroidLoggerAdapter.log(AndroidLoggerAdapter.java:55)
    QRLib: Already saved chunk 2 of 143
07-11 15:39:43.460  13793-22989/com.galois.qrstream D/qrlib﹕ 2014-07-11 15:39:43.466 org.slf4j.impl.AndroidLoggerAdapter.log(AndroidLoggerAdapter.java:55)
    QRLib: Already saved chunk 3 of 143
07-11 15:39:43.465  13793-22989/com.galois.qrstream D/qrlib﹕ 2014-07-11 15:39:43.467 org.slf4j.impl.AndroidLoggerAdapter.log(AndroidLoggerAdapter.java:55)
    QRLib: Already saved chunk 5 of 143
07-11 15:39:43.465  13793-22989/com.galois.qrstream D/qrlib﹕ 2014-07-11 15:39:43.468 org.slf4j.impl.AndroidLoggerAdapter.log(AndroidLoggerAdapter.java:55)
    QRLib: Already saved chunk 4 of 143
07-11 15:39:43.465  13793-22989/com.galois.qrstream D/qrlib﹕ 2014-07-11 15:39:43.469 org.slf4j.impl.AndroidLoggerAdapter.log(AndroidLoggerAdapter.java:55)
    QRLib: Already saved chunk 6 of 143
07-11 15:39:43.465  13793-22989/com.galois.qrstream D/qrstream﹕ changeState state = Fail
07-11 15:39:43.465  13793-13793/com.galois.qrstream D/qrstream﹕ DisplayUpdate.handleMessage Fail
07-11 15:39:43.465  13793-13793/com.galois.qrstream D/AndroidRuntime﹕ Shutting down VM
07-11 15:39:43.465  13793-13793/com.galois.qrstream W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x418c32a0)
07-11 15:39:43.465  13793-22989/com.galois.qrstream E/qrstream﹕ DecodeThread failed to read message. java.io.EOFException
07-11 15:39:43.470  13793-13793/com.galois.qrstream E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at android.widget.Toast.makeText(Toast.java:304)
            at com.galois.qrstream.lib.ReceiveFragment$3.run(ReceiveFragment.java:267)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4898)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
            at dalvik.system.NativeStart.main(Native Method)
donpdonp commented 10 years ago
ReceiveFragment.java:267  
Toast.makeText(getActivity(), R.string.receive_failedTxt, Toast.LENGTH_LONG).show();

The params to makeText are constant except for getActivity(). Its possible this method was called before the Fragment was 'attached' to the Activity.

lcasburn commented 10 years ago

We should just check that getActivity is not null before generating Toast.

donpdonp commented 10 years ago

ok its wrapped in a conditional. I was a bit unsure to wrap the Toast or the whole block, but if there is no Activity, the other UI elements probably arent ready either.

commit 0ad61aea

lcasburn commented 10 years ago

Looks good as is. It makes sense to wrap the whole block. Go ahead and commit.

donpdonp commented 10 years ago

its been committed directly to master.