AlertDialog Holoeverywhere崩溃了吗?

时间:2014-01-25 04:43:37

标签: android android-alertdialog android-holo-everywhere

我正在学习holoeverywhere库>> https://github.com/Prototik/HoloEverywhere/ 我正在尝试alertdialog,但我发生了崩溃......

这个错误..........

01-25 10:45:52.799: E/AndroidRuntime(12308): FATAL EXCEPTION: main
01-25 10:45:52.799: E/AndroidRuntime(12308): java.lang.NullPointerException
01-25 10:45:52.799: E/AndroidRuntime(12308):    at org.holoeverywhere.widget.AlertController.setupContent(AlertController.java:681)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at org.holoeverywhere.widget.AlertController.setupView(AlertController.java:745)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at org.holoeverywhere.widget.AlertController.installContent(AlertController.java:469)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at org.holoeverywhere.app.AlertDialog.onCreate(AlertDialog.java:411)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.app.Dialog.dispatchOnCreate(Dialog.java:307)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.app.Dialog.show(Dialog.java:225)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at com.droidersuin.project.setting.SettingAppSystem.ClearChace(SettingAppSystem.java:196)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at com.droidersuin.project.setting.SettingAppSystem$2.onItemClick(SettingAppSystem.java:137)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.widget.ListView.performItemClick(ListView.java:3755)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at org.holoeverywhere.widget.ListView.performItemClick(ListView.java:635)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1964)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.os.Handler.handleCallback(Handler.java:587)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.os.Looper.loop(Looper.java:130)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at android.app.ActivityThread.main(ActivityThread.java:3687)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at java.lang.reflect.Method.invokeNative(Native Method)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at java.lang.reflect.Method.invoke(Method.java:507)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-25 10:45:52.799: E/AndroidRuntime(12308):    at dalvik.system.NativeStart.main(Native Method)

这是我的代码.........

import org.holoeverywhere.app.Activity;
import org.holoeverywhere.app.AlertDialog;

public class SettingAppSystem extends Activity {
//...
public void onCreate(Bundle savedInstanceState) {
//.....
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Delete Cache?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {  
                       final ProgressDialog progressDialog = ProgressDialog.show(SettingAppSystem.this, "", "Delete Cache...");
                         new Thread() {
                              public void run() {
                                  try {
                                   ImageLoader imgLoader = new ImageLoader(getBaseContext());
                                   ImageLoaderDetailImage imgLoaderDetailImage = new ImageLoaderDetailImage(getBaseContext());
                                   imgLoader.clearCache();
                                   imgLoaderDetailImage.clearCache();
                                  } catch (Exception e) {
                                      Log.e("tag", e.getMessage());
                                  }
                                  progressDialog.dismiss();
                                Thread.currentThread().interrupt();
                              }
                          }.start();

                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                   }
               });
        AlertDialog alert = builder.create();
        alert.show(); 
}
}

当我点击logcat时,错误是 alert.show(); ,如何解决?对不起我的英文

1 个答案:

答案 0 :(得分:0)

尝试作为上下文传递。在您的活动中声明以下内容:

final Context context = this;

然后改变:

new AlertDialog.Builder(this);

要:

new AlertDialog.Builder(context);

----------老答案---------

更改

    AlertDialog alert = builder.create();
    alert.show(); 

builder.show();

作为新警报,您的创建为空。