Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我的程序跳过if语句?_Java_If Statement - Fatal编程技术网

Java 为什么我的程序跳过if语句?

Java 为什么我的程序跳过if语句?,java,if-statement,Java,If Statement,我试着用不同的方法写我的程序,但我想不出来。。即使验证了条件,程序也只执行else下的代码 有人能帮我吗 谢谢 这是我的密码: table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int row = table.getSelectedRow(); int col = table.getSelectedColumn();

我试着用不同的方法写我的程序,但我想不出来。。即使验证了条件,程序也只执行else下的代码 有人能帮我吗 谢谢

这是我的密码:

table.addMouseListener(new MouseAdapter() {

    public void mouseClicked(MouseEvent e) {

        int row = table.getSelectedRow();
        int col = table.getSelectedColumn();
        String path=table.getValueAt(row, col).toString();
        String equipementMOID=txt.getText();

        if(table.isColumnSelected(4) ){
            if(table.getValueAt(row, 3).toString()=="UNIT" ){
                String equipementDate2=comboBox_10.getSelectedItem().toString();
                String xmlFile2=con.XMLSelection(equipementDate2);
                GetNode ne=new GetNode();
                try{
                    String equipementXml2=ne.nodeToString(xmlFile2, equipementMOID);
                    System.out.println(equipementXml2);
                    //GetNodeByPath node=new GetNodeByPath(equipementXml2,path);
                } 
                catch (SAXException | IOException | ParserConfigurationException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }    
            else{
                String equipementDate1=comboBox_9.getSelectedItem().toString();
                String xmlFile1=con.XMLSelection(equipementDate1);
                GetNode ne=new GetNode();
                try{
                    String equipementXml1=ne.nodeToString(xmlFile1, equipementMOID);
                    GetNodeByPath node=new GetNodeByPath(equipementXml1,path);
                } 
                catch (SAXException | IOException | ParserConfigurationException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }         
        }   
    }
});
使用string.equals(string other)函数来比较字符串,而不是==运算符

函数检查字符串的实际内容,==运算符检查对对象的引用是否相等。 如果确实要测试两个字符串是否具有相同的值,则应使用.equals()


条件下尝试此操作

table.getValueAt(row, 3).toString().equals("UNIT")

=
实际检查
字符串
对象的引用(将其视为存储
对象
的位置),而
equals()
检查
如果是
字符串

比较字符串时使用equals(),而不是
==
如果你写代码,我不明白问题是什么?如果您无法理解代码,请根据您的理解修改代码。使用equals()仍无法工作!
table.getValueAt(row, 3).toString().equals("UNIT")