Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.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 单击JTable中的行时出现NullPointerException_Java_Swing_Jtable_Listselectionlistener - Fatal编程技术网

Java 单击JTable中的行时出现NullPointerException

Java 单击JTable中的行时出现NullPointerException,java,swing,jtable,listselectionlistener,Java,Swing,Jtable,Listselectionlistener,如果单击Jtable中的空第8列,我想激活一个按钮。但我明白了: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at records$1.valueChanged(records.java:57) 这是我的密码: tb_records.getSelectionModel().addListSelectionListener(new ListSelectionListener(){

如果单击Jtable中的空第8列,我想激活一个按钮。但我明白了:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at records$1.valueChanged(records.java:57)
这是我的密码:

tb_records.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent event) {

                int row = tb_records.getSelectedRow();
                DefaultTableModel model = (DefaultTableModel)tb_records.getModel();
                String hehe = (String) model.getValueAt(row, 7);

                if(!hehe.equals("")) {
                    b_extend.setEnabled(false);
                }
                else {
                    b_extend.setEnabled(true);
                }
            }
        });
(不是答案,我说的是简单的方法)

  • ListSelectionMode
    更改为
    SINGLE...
    ,则只能选择一行,否则必须在所选行的
    数组中循环

  • 测试
    如果(行>-1)
    ==未选择任何行,如果通过,则可以


  • 为了获得更好的帮助,请尽早发布一个简短的、可运行的、可编译的、带有JTable硬编码值的

  • (不是答案,我说的是简单的方法)

  • ListSelectionMode
    更改为
    SINGLE...
    ,则只能选择一行,否则必须在所选行的
    数组中循环

  • 测试
    如果(行>-1)
    ==未选择任何行,如果通过,则可以


  • 为了获得更好的帮助,请尽早发布一个简短的、可运行的、可编译的、带有JTable硬编码值的

  • (不是答案,我说的是简单的方法)

  • ListSelectionMode
    更改为
    SINGLE...
    ,则只能选择一行,否则必须在所选行的
    数组中循环

  • 测试
    如果(行>-1)
    ==未选择任何行,如果通过,则可以


  • 为了获得更好的帮助,请尽早发布一个简短的、可运行的、可编译的、带有JTable硬编码值的

  • (不是答案,我说的是简单的方法)

  • ListSelectionMode
    更改为
    SINGLE...
    ,则只能选择一行,否则必须在所选行的
    数组中循环

  • 测试
    如果(行>-1)
    ==未选择任何行,如果通过,则可以


  • 为了获得更好的帮助,请尽早发布一个简短的、可运行的、可编译的、带有JTable硬编码值的


  • 我对您的代码做了一些更改,可能会有所帮助

    .(new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent e) {
    
                if (! e.getValueIsAdjusting() ) {
                  ListSelectionModel d = (ListSelectionModel)e.getSource();
                  if(d.getLeadSelectionIndex() != -1){
                       String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
                       b_extend.setEnabled("".equals(hehe));
                  }
                }
    
                }
            });
    

    我对您的代码做了一些更改,可能会有所帮助

    .(new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent e) {
    
                if (! e.getValueIsAdjusting() ) {
                  ListSelectionModel d = (ListSelectionModel)e.getSource();
                  if(d.getLeadSelectionIndex() != -1){
                       String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
                       b_extend.setEnabled("".equals(hehe));
                  }
                }
    
                }
            });
    

    我对您的代码做了一些更改,可能会有所帮助

    .(new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent e) {
    
                if (! e.getValueIsAdjusting() ) {
                  ListSelectionModel d = (ListSelectionModel)e.getSource();
                  if(d.getLeadSelectionIndex() != -1){
                       String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
                       b_extend.setEnabled("".equals(hehe));
                  }
                }
    
                }
            });
    

    我对您的代码做了一些更改,可能会有所帮助

    .(new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent e) {
    
                if (! e.getValueIsAdjusting() ) {
                  ListSelectionModel d = (ListSelectionModel)e.getSource();
                  if(d.getLeadSelectionIndex() != -1){
                       String hehe = (String) model.getValueAt(d.getLeadSelectionIndex(), 7);
                       b_extend.setEnabled("".equals(hehe));
                  }
                }
    
                }
            });
    

    @nachokk-if(!hehe.equals(“”){为了更好的帮助,越早发布一个[SSCCE][1],短的,可运行的,可编译的,带有JTable[1]的硬编码值:作为对
    “.equals(hehe)
    @nachokk-if(!hehe.equals(“”){为了更好的帮助,越早发布一个[SSCCE][1],短的,可运行的,可编译的,带有JTable[1]的硬编码值]:作为快速修复更改为
    “”.equals(hehe)
    @nachokk-if(!hehe.equals(“”){为了更好地帮助,请尽早发布[SSCCE][1],简短、可运行、可编译,带有JTable[1]的硬编码值:作为快速修复更改为
    “”.equals(hee)
    @nachokk-if(!hehe.equals(“”){为了更好地帮助,请尽早发布[SSCCE][1],简短,可运行,可编译,带有JTable[1]的硬编码值:作为对
    的快速修改。等于(呵呵)