我正在尝试实现进度对话框但是我总是得到一个NullPointerException。这是我的一段代码:
ProgressDialog MyDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.allshows);
MyDialog = ProgressDialog.show(AllShowsActivity.this, " ", "Loading, please wait...", true);
Thread thread = new Thread(this);
thread.start();
}
public void run(){
...
handler.sendEmptyMessage(0);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
System.out.println("Being dismissed...");
MyDialog.dismiss();
}
};
有什么想法?这一切都很好,没有进度对话框,所以我想线程内部的内容是不相关的。日志错误是:
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): FATAL EXCEPTION: main
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): java.lang.NullPointerException
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.AbsListView$RecycleBin.getScrapView(AbsListView.java:5698)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.AbsListView.obtainView(AbsListView.java:1940)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.ListView.measureHeightOfChildren(ListView.java:1228)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.ListView.onMeasure(ListView.java:1139)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.View.measure(View.java:10835)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.View.measure(View.java:10835)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.View.measure(View.java:10835)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.LinearLayout.measureVertical(LinearLayout.java:764)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.View.measure(View.java:10835)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1890)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.View.measure(View.java:10835)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.ViewRoot.performTraversals(ViewRoot.java:915)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.view.ViewRoot.handleMessage(ViewRoot.java:2009)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.os.Looper.loop(Looper.java:132)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at android.app.ActivityThread.main(ActivityThread.java:4025)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at java.lang.reflect.Method.invokeNative(Native Method)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at java.lang.reflect.Method.invoke(Method.java:491)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-19 15:45:58.010: ERROR/AndroidRuntime(3186): at dalvik.system.NativeStart.main(Native Method)