我在 android 中有一个微调器,我想检查微调器中的值是否在索引 6 上返回“LAIN-LAIN”,它将显示我的编辑文本,但是当我运行它时,它返回错误,这是我的代码:
ArrayAdapter<String> spinner_bukti = new ArrayAdapter<String>(Pemegang_polis.this, R.layout.spinner_style,identitas);
spinner_bukti.setDropDownViewResource(R.layout.spinner_dropdown);
bukti_identitas_pp.setAdapter(spinner_bukti);
bukti_identitas_pp.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
String Text = bukti_identitas_pp.getSelectedItem().toString();
if (Text=="LAIN-LAIN"){
edit_bukti_lain_pp.setVisibility(View.VISIBLE);
teks_bukti_lain_pp.setVisibility(View.GONE);
}else{
edit_bukti_lain_pp.setVisibility(View.GONE);
teks_bukti_lain_pp.setVisibility(View.VISIBLE);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
这是我的日志:
11-08 15:04:13.329: E/AndroidRuntime(2845): FATAL EXCEPTION: main
11-08 15:04:13.329: E/AndroidRuntime(2845): java.lang.NullPointerException
11-08 15:04:13.329: E/AndroidRuntime(2845): at id.co.ajsmsig.formspaj.Pemegang_polis$2.onItemSelected(Pemegang_polis.java:170)
11-08 15:04:13.329: E/AndroidRuntime(2845): at android.widget.AdapterView.fireOnSelected(AdapterView.java:892)
11-08 15:04:13.329: E/AndroidRuntime(2845): at android.widget.AdapterView.access$200(AdapterView.java:49)
11-08 15:04:13.329: E/AndroidRuntime(2845): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:860)
11-08 15:04:13.329: E/AndroidRuntime(2845): at android.os.Handler.handleCallback(Handler.java:615)
11-08 15:04:13.329: E/AndroidRuntime(2845): at android.os.Handler.dispatchMessage(Handler.java:92)
11-08 15:04:13.329: E/AndroidRuntime(2845): at android.os.Looper.loop(Looper.java:137)
11-08 15:04:13.329: E/AndroidRuntime(2845): at android.app.ActivityThread.main(ActivityThread.java:4895)
11-08 15:04:13.329: E/AndroidRuntime(2845): at java.lang.reflect.Method.invokeNative(Native Method)
11-08 15:04:13.329: E/AndroidRuntime(2845): at java.lang.reflect.Method.invoke(Method.java:511)
11-08 15:04:13.329: E/AndroidRuntime(2845): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
11-08 15:04:13.329: E/AndroidRuntime(2845): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
11-08 15:04:13.329: E/AndroidRuntime(2845): at dalvik.system.NativeStart.main(Native Method)
我不知道我的错在哪里..我希望有人可以帮助我解决我的问题。