AlertDialog的六种创建方式

https://www.cnblogs.com/shen-hua/p/5709663.html
阅读更多

创建AlertDialog产生的错误

08-12

点击按钮显示AlertDialog,代码:rnrn @Overridern public void onClick(View arg0) rn Log.d("","Kliknieto");rn AlertDialog.Builder b = new AlertDialog.Builder(ctx);rn b.setTitle(R.string.camerae);rnrn if(dpm.getCameraDisabled(c))rn rn b.setMessage(R.string.enabled);rn b.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() rn @Overridern public void onClick(DialogInterface dialog, int which) rn dialog.dismiss();rn rn );rn b.setPositiveButton(R.string.senable, new DialogInterface.OnClickListener() rn @Overridern public void onClick(DialogInterface dialog, int which) rnrn //Some code removedrnrn rn );rn rn elsern rn b.setMessage(R.string.disabled);rn b.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() rn @Overridern public void onClick(DialogInterface dialog, int which) rn dialog.dismiss();rn rn );rn b.setPositiveButton(R.string.sdisable, new DialogInterface.OnClickListener() rn @Overridern public void onClick(DialogInterface dialog, int which) rn //Some code removedrn rn );rn rn b.show();rn rnrn变量声明正确,但是不知道为什么会出错:rnrn 08-11 16:24:39.708: E/AndroidRuntime(951): FATAL EXCEPTION: mainrn 08-11 16:24:39.708: E/AndroidRuntime(951): java.lang.NullPointerExceptionrn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.app.AlertDialog$Builder.(AlertDialog.java:359)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at com.radzik.devadmin.MainActivity$5.onClick(MainActivity.java:140)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.view.View.performClick(View.java:4084)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.view.View$PerformClick.run(View.java:16966)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.os.Handler.handleCallback(Handler.java:615)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.os.Handler.dispatchMessage(Handler.java:92)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.os.Looper.loop(Looper.java:137)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at android.app.ActivityThread.main(ActivityThread.java:4745)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at java.lang.reflect.Method.invokeNative(Native Method)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at java.lang.reflect.Method.invoke(Method.java:511)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)rn 08-11 16:24:39.708: E/AndroidRuntime(951): at dalvik.system.NativeStart.main(Native Method)rnrn140行是:rnrn AlertDialog.Builder b = new AlertDialog.Builder(ctx);rn

没有更多推荐了,返回首页