简体   繁体   English

如何处理“ AWT-EventQueue-0” java.lang.NullPointerException?

[英]How to handle “AWT-EventQueue-0” java.lang.NullPointerException?

I am trying to delete a data from JTable and also from text file but got "AWT-EventQueue-0" java.lang.NullPointerException . 我正在尝试从JTable和文本文件中删除数据,但是得到了"AWT-EventQueue-0" java.lang.NullPointerException Please help me, here is my code: 请帮助我,这是我的代码:

private void btndeleteActionPerformed(java.awt.event.ActionEvent evt2){
    deleteRow();            }


    private void deleteRow() 
      {
        dtm = (DefaultTableModel)myjtable.getModel();`EXCEPTION AT THIS LINE `
        int r=myjtable.getSelectedRow();

        String str=myjtable.getValueAt(r,0).toString();


        int row=dtm.getRowCount();     

        try  
        { 
            RandomAccessFile r1=new RandomAccessFile("C:\\Myfile.txt","rw");
            RandomAccessFile r2=new RandomAccessFile("C:\\TempFile.txt","rw");
            FileWriter myfile = new FileWriter("C:\\TempFile.txt",true);
            PrintWriter outStream = new PrintWriter(myfile);
            FileWriter myfile1 = new FileWriter("C:\\Myfile.txt",true);
            PrintWriter outStream1 = new PrintWriter(myfile1);

            r2.setLength(0);


            String regexp = "[|]+";
            for(int i=0;i<row;i++)
            {   
             String str1=r1.readLine().trim();
             String[] line = str1.split(regexp);
            if(line[0].compareTo(str)!=0)
            {
                outStream.print(str1);
                outStream.print("\r\n");

            }
            }
            outStream.close();

            r2.seek(0);
            r1.setLength(0);
            for(int i=0;i<row-1;i++)
            {   

             String str1=r2.readLine().trim();


            {
                outStream1.print(str1);
                outStream1.print("\r\n");

            }
            }
            r1.close();
            r2.close();
            outStream1.close();
            readFile();
        }
        catch (IOException e) {     
            System.out.println(e);     
        }



        }

My guess is that you are shadowing the myjtable variable. 我的猜测是您正在隐藏myjtable变量。 This means you defined it as an instance variable in your class and as a local variable somewhere in your code. 这意味着您将其定义为类中的实例变量以及代码中某处的局部变量。 So you probably have code something like: 因此,您可能具有类似以下的代码:

JTable myjtable;  // the instance variable
.
.
.
.
JTable myjtable = new JTable(...); // local variable

You don't want a local variable so the code should be: 您不需要局部变量,因此代码应为:

myjTable = new JTable(...);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException - Java: Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException Java-线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException - Java - Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException Getter和Setter Java AWT-EventQueue-0 java.lang.NullPointerException - Getter and Setter Java AWT-EventQueue-0 java.lang.NullPointerException 线程““ AWT-EventQueue-0””中的Java异常java.lang.NullPointerException - Java Exception in thread '“AWT-EventQueue-0”' java.lang.NullPointerException java中的“AWT-EventQueue-0”java.lang.NullPointerException - “AWT-EventQueue-0” java.lang.NullPointerException in java 线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException Java - Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException Java 线程“AWT-EventQueue-0”中的异常java.lang.NullPointerException? Java的 - Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException? Java 线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException - Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException eclipse:线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException - eclipse : Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException “AWT-EventQueue-0”java.lang.NullPointerException错误的原因 - Reason for “AWT-EventQueue-0” java.lang.NullPointerException error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM