So... Other people on this list have attempted to help prior to this reply. They are much nicer than I.
1. You *never* asked a question. You posted a bit of code and indicated there was an error. You didn't indicate that you tried to figure out the error or anything else. The people who subscribe to this list aren't your parents and are under no obligation to try to read your mind (assuming your parents have that obligation) to solve your _unstated_ problems. 2. This mailing list is to discuss Netbeans issues. Basic java problems really shouldn't be addressed here, although I might be in the minority in this mailing list with that opinion. There are ample places other than this list to find an answer to your implied problem. -- Mark A. Flacy mfl...@verizon.net On 2022 M05 22, Sun 17:52:55 CDT Zulfi Khan wrote: > Hi, > I have written the following code: > /* > * Click > nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to > change this license * Click > nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/ja > va/${packagePath}/${mainClassName}.java to edit this template */ > > package com.mycompany.add2strjop; > import javax.swing.*; > import java.lang.NumberFormatException; > import java.io.FileWriter; > import java.io.FileReader; > import java.io.BufferedWriter; > import java.io.BufferedReader; > import java.io.IOException; > public class Add2StrJOp { > BufferedReader BF= null; > BufferedReader BW= null; > String str = "test"; > > public static void main(String args[]){ > try{ > FileReader file = new FileReader("abc.txt"); > BF = new BufferedReader(file);//E > //BF= new BufferedReader(new FileReader("abc.txt")); > while ((str = BF.readLine())!=null){//E > JOptionPane.showMessageDialog(null, str);//E > //JOptionPane.showMessageDialog(null, "hello World"); > //BF.clos() > } > }catch(IOException e){ > e.printStackTrace(); > } > finally{ > try{ > if( BF!=null){//E > BF.close();//E > } > }catch(IOException e) { > e.printStackTrace(); > } > }//finally > try{ > BW = new BufferedWriter(new FileWriter("abc.txt"));//E > String str= "This is a test"; > BW.write(str);//E > BW.close();//E > }catch(IOException e) { > e.printStackTrace(); > } > } > } > > > I have commented the lines as //E where I am getting the error "Non-static > variable cannot be referenced from static context. Zulfi.