无法启动活动组件信息Null Pointer Exception ProgressDialog

时间:2014-08-01 17:39:39

标签: android

我得到了这个空指针异常。这里的每个线程我发现它与xml对象有关,但我的崩溃与Progress Dialog有关。这是代码

 public class ActivityCommissions extends Activity {
ProgressDialog pdialog;
AlertDialogManager alert = new AlertDialogManager();
ListView list;
public CommissionsAdapter adapter;
EditText editsearch;
private ImageView refresh;
static ArrayList<Commission> arraylist = new ArrayList<Commission>();

String pageToken;
GPSTracker gpstracker;
static double latitude, longitude;

ConnectionDetector cd;

 }
 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.commissions);
    /* DO IRRELEVANT STUFF */
    search();
}
    @SuppressWarnings("unused")
private void Search() {
    //CLEAR SEARCH RESULTS
    arraylist.clear();

    /* CRASHES HERE */
    pdialog = ProgressDialog.show(this.getParent(), "", "Retrieving Commissions...");

    /* INTIALIZE REQUEST QUEUE */
    RequestQueue queue = Volley.newRequestQueue(this);

    /* latitude && longitude */
    latitude = gpstracker.getLatitude();
    longitude = gpstracker.getLongitude();

    /* MORE IRRELEVANT STUFF */
 }

它在读取

的行上崩溃
 pdialog = ProgressDialog.show(this.getParent(), "", "Retrieving Commissions...");

这是错误日志

08-01 12:37:19.626: W/dalvikvm(19602): threadid=1: thread exiting with uncaught exception (group=0x40ab0a08)
08-01 12:37:19.636: E/AndroidRuntime(19602): FATAL EXCEPTION: main
08-01 12:37:19.636: E/AndroidRuntime(19602): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appusa1/com.appusa1.ActivityCommissions}: java.lang.NullPointerException
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2260)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.os.Looper.loop(Looper.java:156)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ActivityThread.main(ActivityThread.java:5045)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at java.lang.reflect.Method.invokeNative(Native Method)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at java.lang.reflect.Method.invoke(Method.java:511)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at dalvik.system.NativeStart.main(Native Method)
08-01 12:37:19.636: E/AndroidRuntime(19602): Caused by: java.lang.NullPointerException
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.AlertDialog.<init>(AlertDialog.java:98)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ProgressDialog.show(ProgressDialog.java:110)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ProgressDialog.show(ProgressDialog.java:99)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ProgressDialog.show(ProgressDialog.java:94)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at com.appusa1.ActivityCommissions.Search(ActivityCommissions.java:127)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at com.appusa1.ActivityCommissions.onCreate(ActivityCommissions.java:87)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.Activity.performCreate(Activity.java:4543)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
08-01 12:37:19.636: E/AndroidRuntime(19602):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
08-01 12:37:19.636: E/AndroidRuntime(19602):    ... 11 more

知道为什么它会在pdialog上崩溃吗?任何帮助是极大的赞赏。是的,我已经导入了ProgressDialog类

1 个答案:

答案 0 :(得分:2)

根据ProgressDialog Context 显示ProgressDialog所需的public static ProgressDialog show (Context context, CharSequence title, CharSequence message)

见这个

Context

所以,

this.getParent()

中使用pdialog = ProgressDialog.show(this.getParent(), "", "Retrieving Commissions...");代替ActivityCommissions.this

那是

{p> this.getParent()而不是pdialog = ProgressDialog.show(this.getParent(), "", "Retrieving Commissions...");

中的ProgressDialog.show(ActivityCommissions.this, "", "Retrieving Commissions...");

所以应该是这样的

{{1}}