我打電話方法AlertUser.alertUser(getActivity());
具有alertDialog從片段,但它拋出NPE錯誤NPE同時創造alerdialog
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(flag==false)
{
progressDialog.cancel();
AlertUser.alertUser(getActivity());
cancel(true);
}
}
}, 30000);
alertUser方法:
public static void alertUser(Context context)
{
AlertDialog.Builder alertDialog=new AlertDialog.Builder(context);
alertDialog.setTitle("Connection failure...!"+"\n");
alertDialog.setMessage("\n"+"It looks like you have lost network connection. Please check your network connection or wait to re-connect"+"\n");
// Setting "Yes" Button
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
/*Intent noNetwork=new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
startActivityForResult(noNetwork,1443);*/
}
});
alertDialog.show();
}
logcat的
02-05 15:47:06.440: E/AndroidRuntime(12050): FATAL EXCEPTION: main
02-05 15:47:06.440: E/AndroidRuntime(12050): java.lang.NullPointerException
02-05 15:47:06.440: E/AndroidRuntime(12050): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
02-05 15:47:06.440: E/AndroidRuntime(12050): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:359)
02-05 15:47:06.440: E/AndroidRuntime(12050): at com.abs.deliveryboy.AlertUser.alertUser(AlertUser.java:11)
02-05 15:47:06.440: E/AndroidRuntime(12050): at com.abs.deliveryboy.NewOrdersFragment$NewOrderTask$1.run(NewOrdersFragment.java:159)
02-05 15:47:06.440: E/AndroidRuntime(12050): at android.os.Handler.handleCallback(Handler.java:615)
02-05 15:47:06.440: E/AndroidRuntime(12050): at android.os.Handler.dispatchMessage(Handler.java:92)
02-05 15:47:06.440: E/AndroidRuntime(12050): at android.os.Looper.loop(Looper.java:137)
02-05 15:47:06.440: E/AndroidRuntime(12050): at android.app.ActivityThread.main(ActivityThread.java:4800)
02-05 15:47:06.440: E/AndroidRuntime(12050): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 15:47:06.440: E/AndroidRuntime(12050): at java.lang.reflect.Method.invoke(Method.java:511)
02-05 15:47:06.440: E/AndroidRuntime(12050): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-05 15:47:06.440: E/AndroidRuntime(12050): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-05 15:47:06.440: E/AndroidRuntime(12050): at dalvik.system.NativeStart.main(Native Method)
AlertUser.java的第11行是什麼? – Michael