当我尝试在用户按下“Eliminar”(删除)按钮时显示对话框时,我的应用程序崩溃:
botonEliminar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder builder = new AlertDialog.Builder(
getApplicationContext());
builder.setMessage("¿Seguro que quieres eliminar?")
.setCancelable(false)
.setNegativeButton("Eliminar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SQLiteDatabase database = gestor.getWritableDatabase();
if (database != null) {
database.execSQL("DELETE FROM Organizaciones WHERE nombre_org = '"
+ name + "'");
database.close();
}
Intent intent = new Intent(
Consultar_organizacion.this,
MainActivity.class);
Consultar_organizacion.this
.startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
你能帮忙吗?我不知道出了什么问题。
编辑:这是logcat,看起来问题与“token null”相关,但我不知道:
06-12 15:16:59.776: W/dalvikvm(2343): threadid=1: thread exiting with uncaught exception (group=0x409fa1f8)
06-12 15:16:59.776: E/AndroidRuntime(2343): FATAL EXCEPTION: main
06-12 15:16:59.776: E/AndroidRuntime(2343): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.view.ViewRootImpl.setView(ViewRootImpl.java:522)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.app.Dialog.show(Dialog.java:285)
06-12 15:16:59.776: E/AndroidRuntime(2343): at com.example.project.Consultar_organizacion$1.onClick(Consultar_organizacion.java:87)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.view.View.performClick(View.java:3511)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.view.View$PerformClick.run(View.java:14109)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.os.Handler.handleCallback(Handler.java:605)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.os.Handler.dispatchMessage(Handler.java:92)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.os.Looper.loop(Looper.java:137)
06-12 15:16:59.776: E/AndroidRuntime(2343): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-12 15:16:59.776: E/AndroidRuntime(2343): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 15:16:59.776: E/AndroidRuntime(2343): at java.lang.reflect.Method.invoke(Method.java:511)
06-12 15:16:59.776: E/AndroidRuntime(2343): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-12 15:16:59.776: E/AndroidRuntime(2343): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-12 15:16:59.776: E/AndroidRuntime(2343): at dalvik.system.NativeStart.main(Native Method)