Android -bug runOnUiThread
- bug:
09-06 14:28:17.407 4630-4719/com.supoin.rfiddemo E/AndroidRuntime: FATAL EXCEPTION: Thread-4
Process: com.supoin.rfiddemo, PID: 4630
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)' on a null object reference
at com.supoin.rfiddemo.fragment.WriteLockFragment$2.run(WriteLockFragment.java:252)
at java.lang.Thread.run(Thread.java:764)
- stack overflow 同样问题解答:
-
answer:
I'm almost sure that this is caused when the thread finish its work but the activity is no longer visible.
you should check if the
getActicity()
call return null, and Put
if(getActivity() == null)
return;