我的 DIALOG 中有一个微调器,我想在单击“确定”按钮时选择该项目。每次我在对话框中按“确定”。NullPointerException 总是出现。
注意:我的微调器位于对话框中。
builder.setView(inflater.inflate(R.layout.dialog_sendtransfer_layout, null))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
fromSpin.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
fromSite = arg0.getItemAtPosition(arg2).toString();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
} });
//fromSite = fromSpin.getItemAtPosition(fromSpin.getSelectedItemPosition()).toString();
//toSite = toSpin.getItemAtPosition(toSpin.getSelectedItemPosition()).toString();
Toast.makeText(getBaseContext(),"From: " + fromSite, Toast.LENGTH_LONG).show();
}
LOGCAT
02-13 10:57:08.513: E/AndroidRuntime(2430): FATAL EXCEPTION: main
02-13 10:57:08.513: E/AndroidRuntime(2430): java.lang.NullPointerException
02-13 10:57:08.513: E/AndroidRuntime(2430): at com.aws.ojt.activities.TransferCore$1.onClick(TransferCore.java:132)
02-13 10:57:08.513: E/AndroidRuntime(2430): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
02-13 10:57:08.513: E/AndroidRuntime(2430): at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 10:57:08.513: E/AndroidRuntime(2430): at android.os.Looper.loop(Looper.java:137)
02-13 10:57:08.513: E/AndroidRuntime(2430): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-13 10:57:08.513: E/AndroidRuntime(2430): at java.lang.reflect.Method.invokeNative(Native Method)
02-13 10:57:08.513: E/AndroidRuntime(2430): at java.lang.reflect.Method.invoke(Method.java:511)
02-13 10:57:08.513: E/AndroidRuntime(2430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-13 10:57:08.513: E/AndroidRuntime(2430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-13 10:57:08.513: E/AndroidRuntime(2430): at dalvik.system.NativeStart.main(Native Method)