我的If声明让一个Force关闭了

时间:2012-03-08 05:13:57

标签: java android if-statement

    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)

1 个答案:

答案 0 :(得分:2)

使用 trans.setText(“”)而不是trans.setText(null)更改您的其他内容;