我在谷歌上搜索,但没有得到积极的东西。我不知道为什么我在警报 dailog.create() 上收到空指针异常
我正在单击一个按钮创建一个 dailog,该按钮具有一个列表视图和一个线性布局中的按钮
viewReport.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//created listMap
final String value[]=getKArrayFromMap(listMap);
final AlertDialog alertDialog = new AlertDialog.Builder(
getParent()).create();
LinearLayout linearLayout = new LinearLayout(getParent());
linearLayout.setOrientation(LinearLayout.VERTICAL);
Button ok=new Button(getParent());
final ListView lv = new ListView(getParent());
// simple_list_item_checked
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getParent(),
android.R.layout.simple_list_item_multiple_choice, value);
lv.setAdapter(adapter);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
linearLayout.addView(lv);
linearLayout.addView(ok);
alertDialog.setView(linearLayout);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// some work
}
);
alertDialog.show();
}
});
在以下位置出现空指针异常:
09-27 11:37:37.033: E/AndroidRuntime(1997): FATAL EXCEPTION: main
09-27 11:37:37.033: E/AndroidRuntime(1997): java.lang.NullPointerException
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:359)
09-27 11:37:37.033: E/AndroidRuntime(1997): at com.cloudchowk.his.doctor.laboratory.BindDetailsActivity$BackGroundProcess$6.onClick(BindDetailsActivity.java:794)
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.view.View.performClick(View.java:4084)
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.view.View$PerformClick.run(View.java:16966)
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.os.Handler.handleCallback(Handler.java:615)
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.os.Looper.loop(Looper.java:137)
09-27 11:37:37.033: E/AndroidRuntime(1997): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-27 11:37:37.033: E/AndroidRuntime(1997): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 11:37:37.033: E/AndroidRuntime(1997): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 11:37:37.033: E/AndroidRuntime(1997): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-27 11:37:37.033: E/AndroidRuntime(1997): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-27 11:37:37.033: E/AndroidRuntime(1997): at dalvik.system.NativeStart.main(Native Method)
第 794 行:
final AlertDialog alertDialog = new AlertDialog.Builder(
getParent()).create();