作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Button s2;
AutoCompleteTextView tran;
//Spinner lang;
EditText trans;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.translate);
s2= (Button) findViewById(R.id.button1);
tran= (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
trans = (EditText) findViewById(R.id.editText1);
s2.setOnClickListener(new OnClickListener(){
public void onClick(View dap) {
String input;
String output= null;
input = tran.getText().toString();
if ("Love".equals(input)){
trans.setText("Italian: Amore"+"\n Spanish: Amor"+"\n Japanese: ai / koi"+"\n Mandarin: ai");
}
else
{trans.setText(null);}
我已经阅读了很多有关 if 语句的内容,并且我使用了这个 if ("Love".equals(input))
代码。每次我单击按钮(s2)时,我都会强制关闭。我的 if 语句有什么问题吗?
这些是出现在我的 logcat 中的行。
03-08 05:50:40.952: D/Vold(29): Volume sdcard state changing 0 (No-Media) -> 1 (Idle-Unmounted)
03-08 05:50:40.992: W/Vold(29): No UMS switch available
03-08 05:50:41.072: D/qemud(38): fdhandler_accept_event: accepting on fd 10
03-08 05:50:41.072: D/qemud(38): created client 0xe078 listening on fd 8
03-08 05:50:41.092: D/qemud(38): fdhandler_event: disconnect on fd 8
03-08 05:50:41.222: D/qemud(38): fdhandler_accept_event: accepting on fd 10
03-08 05:50:41.222: D/qemud(38): created client 0xf028 listening on fd 8
03-08 05:50:41.232: D/qemud(38): client_fd_receive: attempting registration for service 'gsm'
03-08 05:50:41.232: D/qemud(38): client_fd_receive: -> received channel id 1
03-08 05:50:41.242: D/qemud(38): client_registration: registration succeeded for client 1
03-08 05:50:41.443: D/qemud(38): fdhandler_accept_event: accepting on fd 10
03-08 05:50:41.443: D/qemud(38): created client 0x10fd8 listening on fd 11
03-08 05:50:41.472: D/qemud(38): client_fd_receive: attempting registration for service 'boot-properties'
03-08 05:50:41.472: D/qemud(38): client_fd_receive: -> received channel id 2
03-08 05:50:41.482: D/qemud(38): client_registration: registration succeeded for client 2
03-08 05:50:41.482: I/qemu-props(54): connected to 'boot-properties' qemud service.
03-08 05:50:41.492: I/qemu-props(54): received: dalvik.vm.heapsize=24m
03-08 05:50:41.522: I/qemu-props(54): received: qemu.sf.lcd_density=240
03-08 05:50:41.542: I/qemu-props(54): received: qemu.hw.mainkeys=1
03-08 05:50:41.562: I/qemu-props(54): received: qemu.sf.fake_camera=back
03-08 05:50:41.602: I/qemu-props(54): received:
03-08 05:50:41.602: I/qemu-props(54): invalid format, ignored.
03-08 05:50:44.592: D/AndroidRuntime(33): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-08 05:50:44.612: D/AndroidRuntime(33): CheckJNI is ON
03-08 05:50:46.853: I/(34): ServiceManager: 0xacd0
03-08 05:50:46.853: D/AudioHardwareInterface(34): setMode(NORMAL)
03-08 05:50:46.913: I/CameraService(34): CameraService started: pid=34
03-08 05:50:46.992: I/AudioFlinger(34): AudioFlinger's thread 0xb3b8 ready to run
03-08 05:50:47.254: D/AndroidRuntime(33): --- registering native functions ---
03-08 05:50:49.533: I/SamplingProfilerIntegration(33): Profiler is disabled.
03-08 05:50:49.783: I/Zygote(33): Preloading classes...
03-08 05:50:49.793: E/Zygote(33): setreuid() failed. errno: 2
03-08 05:50:49.843: D/dalvikvm(33): GC_EXPLICIT freed 821 objects / 47496 bytes in 41ms
03-08 05:51:40.743: E/BatteryService(68): usbOnlinePath not found
03-08 05:51:40.743: E/BatteryService(68): batteryVoltagePath not found
03-08 05:51:40.753: E/BatteryService(68): batteryTemperaturePath not found
03-08 05:51:40.823: I/sysproc(68): Entered system_init()
03-08 05:51:40.823: I/sysproc(68): ServiceManager: 0x11d650
03-08 05:51:40.856: I/SurfaceFlinger(68): SurfaceFlinger is starting
03-08 05:51:40.863: I/SurfaceFlinger(68): SurfaceFlinger's main thread ready to run. Initializing graphics H/W...
03-08 05:51:40.903: E/SurfaceFlinger(68): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
03-08 05:51:41.003: I/gralloc(68): using (fd=25)
最佳答案
使用 trans.setText("") 更改 else,而不是 trans.setText(null);
关于java - 我的 If 语句强制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9613217/
我是一名优秀的程序员,十分优秀!