Java 我的If语句有一个力

Java 我的If语句有一个力,java,android,if-statement,Java,Android,If Statement,我读了很多关于if语句的书,我使用了这个if(“Love.equals(input))code。每次单击按钮(s2),我都会强制关闭。我的if语句有什么问题吗 这些是我的日志中出现的行 Button s2; AutoCompleteTextView tran; //Spinner lang; EditText trans; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceSt

我读了很多关于if语句的书,我使用了这个
if(“Love.equals(input))
code。每次单击按钮(s2),我都会强制关闭。我的if语句有什么问题吗

这些是我的日志中出现的行

    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);}   
03-08 05:50:40.952:D/Vold(29):卷SD卡状态更改0(无介质)->1(空闲卸载)
03-08 05:50:40.992:W/Vold(29):没有可用的UMS开关
03-08 05:50:41.072:D/qemud(38):fdhandler_accept_事件:在fd 10上接受
03-08 05:50:41.072:D/qemud(38):创建了在fd 8上侦听的客户端0xe078
03-08 05:50:41.092:D/qemud(38):FDU事件:在fd 8上断开
03-08 05:50:41.222:D/qemud(38):fdhandler_accept_事件:在fd 10上接受
03-08 05:50:41.222:D/qemud(38):创建了在fd 8上侦听的客户端0xf028
03-08 05:50:41.232:D/qemud(38):客户端接收:正在尝试注册服务“gsm”
03-08 05:50:41.232:D/qemud(38):客户端接收:->接收到的通道id 1
03-08 05:50:41.242:D/qemud(38):客户端注册:客户端1的注册成功
03-08 05:50:41.443:D/qemud(38):fdhandler_accept_事件:在fd 10上接受
03-08 05:50:41.443:D/qemud(38):已创建客户端0x10fd8,正在FD11上侦听
03-08 05:50:41.472:D/qemud(38):客户端接收:正在尝试注册服务“启动属性”
03-08 05:50:41.472:D/qemud(38):客户端接收:->接收到的通道id 2
03-08 05:50:41.482:D/qemud(38):客户端注册:客户端2的注册成功
03-08 05:50:41.482:I/qemu道具(54):已连接到“启动属性”qemud服务。
03-08 05:50:41.492:I/qemu道具(54):收到:dalvik.vm.heapsize=24m
03-08 05:50:41.522:I/qemu道具(54):接收:qemu.sf.lcd_密度=240
03-08 05:50:41.542:I/qemu道具(54):接收到:qemu.hw.mainkeys=1
03-08 05:50:41.562:I/qemu道具(54):收到:qemu.sf.fake_camera=back
03-08 05:50:41.602:I/qemu道具(54):收到:
03-08 05:50:41.602:I/qemu道具(54):格式无效,已忽略。

03-08 05:50:44.592:D/AndroidRuntime(33):>>>>>>>>>>>>>>>>>AndroidRuntime开始用trans.setText(“”代替trans.setText(null)更改您的else

我非常确定
input=tran.getText().toString()
应该是
trans
,而不是
trans
,并且在第一个
'trans
处有一个额外的引号。但我猜这些都是复制/粘贴错误。如果不是,我强烈怀疑这是你的问题。如果声明看起来不错。关于前一行,
tran
是否已初始化(非空)?tran=(AutoCompleteTextView)findViewById(R.id.AutoCompleteTextView 1);这是我的初始化,我的tran是输入字。trans是要在编辑文本中显示的已翻译单词。在我的帖子里(')被打错了。从外观上看,它应该是好的,但它总是关闭。谢谢。按钮s2;自动完成文本视图转换;编辑文本转换;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)这是我的初始化。很难说-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)