Question

i'm learn holoeverywhere library >> https://github.com/Prototik/HoloEverywhere/ i'm try alertdialog, but i get crashes ..

this the error ..........

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)

and this is my code.........

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(); 
}
}

when i click logcat , the error is alert.show(); , how fix it ? sorry for my english

Was it helpful?

Solution

Try passing as a context. Declare the following in your activity:

final Context context = this;

Then change:

new AlertDialog.Builder(this);

To:

new AlertDialog.Builder(context);

----------OLD ANSWER---------

Change

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

To

builder.show();

As the new alert your creating is null.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top