dybarsky / spots-dialog

Android AlertDialog with moving dots progress indicator
MIT License
1.08k stars 242 forks source link

้hey guy i error codeing spotsDialog java.lang.NullPointerException: #20

Closed PongPloy2016 closed 7 years ago

PongPloy2016 commented 7 years ago

I catch error progressbar

if (spotsDialog != null) {

                spotsDialog.dismiss();
                spotsDialog = null;
            } else {
                spotsDialog.dismiss();
                spotsDialog = null;
            }

and show logcaat

Process: th.co.siamkubota.kubota, PID: 24287 java.lang.NullPointerException: Attempt to invoke virtual method 'void dmax.dialog.SpotsDialog.dismiss()' on a null object reference at th.co.siamkubota.kubota.fragment.UnfinishTaskFragment$1.onPostExecute(UnfinishTaskFragment.java:308) at th.co.siamkubota.kubota.fragment.UnfinishTaskFragment$1.onPostExecute(UnfinishTaskFragment.java:221) at android.os.AsyncTask.finish(AsyncTask.java:636) at android.os.AsyncTask.access$500(AsyncTask.java:177) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6856) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

dybarsky commented 7 years ago

Hi! You have a wrong logic. I believe else block is unnecessary :)

matloobn73 commented 6 years ago

If (spotsDialog != Null){ //If spotsDialog is not null. spotsDialog.dismiss; spotsDialog = null; }else{ //If spotsDialog is null. //You can't do anything with spotsDialog as it is null. //You don't have to call spotsDialog.dismiss as it is already null and hence dismissed. }

PongPloy2016 commented 6 years ago

If (spotsDialog != Null){ //If spotsDialog is not null. spotsDialog.dismiss; spotsDialog = null; }else{ //If spotsDialog is null. //You can't do anything with spotsDialog as it is null. //You don't have to call spotsDialog.dismiss as it is already null and hence dismissed. }

thank you bro i check null
If (spotsDialog != Null){ ..... }

and run project and show catch error In perhaps : Attempt to invoke virtual method 'void dmax.dialog.SpotsDialog.dismiss()' on a null object reference to some time