You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Zulfi Khan <zu...@yahoo.com.INVALID> on 2022/05/22 22:52:55 UTC

BufferedReader and BufferedWriter : non-static variable cannot be accessed from the static context

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/java/${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.



Re: BufferedReader and BufferedWriter : non-static variable cannot be accessed from the static context

Posted by Phil L <ph...@gmail.com>.
Try declaring BF, BW and test inside the main method or declare them as 
public static.

On 5/23/22 01:46, John Barrow wrote:
> I am relatively new to Java, and get this occasionally myself due to 
> the "static main" method being typed within the class.
>
> The issue is that you are trying to access "BF" and "str" that exist 
> inside a class, from a static environment (main). I think it would 
> have helped if the exception had been a little more explicit, 
> mentioning the fields that were at fault.
>
> If you were accessing the class from another source file (class) you 
> would first have to create an instance, i.e.
>
> Add2StrJOp myAdd2StrJOp = new Add2StrJOp();
>
> Then you could access "BF" and "str" as
>
> myAdd2StrJOp.BF and myAdd2StrJOp.str.
>
> As the main method is a static method, it also needs to create an 
> instance of Add2StrJOp using "new" before you can access the fields 
> within the class, just as if using your class from an external source 
> file.
>
> So add the line above at the top of your main method, just after the 
> "try {" line and then prefix the class fields with your newly created 
> instance variable to reference them.
>
> Hope that helps.
>
> John
>
> On Sun, 22 May 2022, 23:53 Zulfi Khan, <zu...@yahoo.com.invalid> 
> 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/java/${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.
>
>

Re: BufferedReader and BufferedWriter : non-static variable cannot be accessed from the static context

Posted by John Barrow <jb...@gmail.com>.
I am relatively new to Java, and get this occasionally myself due to the
"static main" method being typed within the class.

The issue is that you are trying to access "BF" and "str" that exist inside
a class, from a static environment (main). I think it would have helped if
the exception had been a little more explicit, mentioning the fields that
were at fault.

If you were accessing the class from another source file (class) you would
first have to create an instance, i.e.

Add2StrJOp myAdd2StrJOp = new Add2StrJOp();

Then you could access "BF" and "str" as

myAdd2StrJOp.BF and myAdd2StrJOp.str.

As the main method is a static method, it also needs to create an instance
of Add2StrJOp using "new" before you can access the fields within the
class, just as if using your class from an external source file.

So add the line above at the top of your main method, just after the "try
{" line and then prefix the class fields with your newly created instance
variable to reference them.

Hope that helps.

John

On Sun, 22 May 2022, 23:53 Zulfi Khan, <zu...@yahoo.com.invalid> 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/java/${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.
>
>
>

Re: BufferedReader and BufferedWriter : non-static variable cannot be accessed from the static context

Posted by Laszlo Kishalmi <la...@gmail.com>.
On 5/24/22 08:41, Ernie Rael wrote:
>
> On 5/23/22 11:04 PM, slipbits wrote:
>>
>> It is true that there other people on this list nicer than you. But 
>> let's look at your reply for a second. You provided no help, only 
>> criticism.
>>
> IMO, that's not accurate. If someone wants to succeed as a programmer, 
> they need to find solutions of all kinds. And when they get stuck and 
> need to reach out, they should "show their work" and put some thought 
> into their question.
>
> Something about teaching them to fish rather than giving them a fish 
> comes to mind.
>
> I find it hard to believe that they didn't know this wasn't a NetBeans 
> list. If they truly didn't, then the most help might be to give them 
> some hints on how to best fish the internet sea.


Well, I'm also member of the NetBeans Telegram group, and I have a 
feeling, that the strongest foothold of NetBeans is in the academics as 
a primary tool to teach Java. After all, it's free, works 
out-of-the-box, and the provided Ant projects templates allows students 
to create their first simple programs without the need to learn anything 
about how to deal with the Java Runtime and packaging. I have the 
feeling that many of these students are not necessary would like to be a 
real developer. They just want to have their exam done / get some 
credits. NetBeans is often synonym to Java, so they often end up posting 
some "interesting" things here and NetBeans Telegram group as well.

Is it annoying to see such questions from time to time? As a 
professional, I'd say yes, though it is not an obligation to anyone to 
answer or interfere. This guy had his answers, so let him be happy with 
those. I think it is Ok to be harsh/raw in your answers as long as they 
are constructive.


>
> -ernie
>
>> The person asking the question wanted help. Rather than your acerbic 
>> answer, you might have provided some aid and direction. You did say 
>> that this list is for Netbeans issues only. That is help. You did say 
>> that there are other places to look, with an implied criticism that 
>> no looking was done. Moreover, you neglected to mention any single 
>> place where help could have been found.
>>
>> In my experience on this list, I have found many people who tried to 
>> be helpful. The person asking the question was not asking for a 
>> fight, and probably did not know the fundamental purpose of this 
>> list. The question asker would have certainly gone elsewhere if it 
>> was known that this list was for Netbeans, not Java.
>>
>> Your comments are unwarranted and not helpful. If you felt annoyed 
>> you should not have commented, or been more gracious in your comments.
>>
>> art
>>
>> On 5/23/2022 9:52 PM, Mark A. Flacy wrote:
>>>
>>> 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
>>>
>>> mflacy@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.
>>>
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org
> For additional commands, e-mail: users-help@netbeans.apache.org
>
> For further information about the NetBeans mailing lists, visit:
> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org
For additional commands, e-mail: users-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: BufferedReader and BufferedWriter : non-static variable cannot be accessed from the static context

Posted by Ernie Rael <er...@raelity.com>.
On 5/23/22 11:04 PM, slipbits wrote:
>
> It is true that there other people on this list nicer than you. But 
> let's look at your reply for a second. You provided no help, only 
> criticism.
>
IMO, that's not accurate. If someone wants to succeed as a programmer, 
they need to find solutions of all kinds. And when they get stuck and 
need to reach out, they should "show their work" and put some thought 
into their question.

Something about teaching them to fish rather than giving them a fish 
comes to mind.

I find it hard to believe that they didn't know this wasn't a NetBeans 
list. If they truly didn't, then the most help might be to give them 
some hints on how to best fish the internet sea.

-ernie

> The person asking the question wanted help. Rather than your acerbic 
> answer, you might have provided some aid and direction. You did say 
> that this list is for Netbeans issues only. That is help. You did say 
> that there are other places to look, with an implied criticism that no 
> looking was done. Moreover, you neglected to mention any single place 
> where help could have been found.
>
> In my experience on this list, I have found many people who tried to 
> be helpful. The person asking the question was not asking for a fight, 
> and probably did not know the fundamental purpose of this list. The 
> question asker would have certainly gone elsewhere if it was known 
> that this list was for Netbeans, not Java.
>
> Your comments are unwarranted and not helpful. If you felt annoyed you 
> should not have commented, or been more gracious in your comments.
>
> art
>
> On 5/23/2022 9:52 PM, Mark A. Flacy wrote:
>>
>> 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
>>
>> mflacy@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.
>>
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org
For additional commands, e-mail: users-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: BufferedReader and BufferedWriter : non-static variable cannot be accessed from the static context

Posted by slipbits <sl...@slipbits.com>.
It is true that there other people on this list nicer than you. But 
let's look at your reply for a second. You provided no help, only 
criticism. The person asking the question wanted help. Rather than your 
acerbic answer, you might have provided some aid and direction. You did 
say that this list is for Netbeans issues only. That is help. You did 
say that there are other places to look, with an implied criticism that 
no looking was done. Moreover, you neglected to mention any single place 
where help could have been found.

In my experience on this list, I have found many people who tried to be 
helpful. The person asking the question was not asking for a fight, and 
probably did not know the fundamental purpose of this list. The question 
asker would have certainly gone elsewhere if it was known that this list 
was for Netbeans, not Java.

Your comments are unwarranted and not helpful. If you felt annoyed you 
should not have commented, or been more gracious in your comments.

art

On 5/23/2022 9:52 PM, Mark A. Flacy wrote:
>
> 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
>
> mflacy@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.
>
>
>

Re: BufferedReader and BufferedWriter : non-static variable cannot be accessed from the static context

Posted by "Mark A. Flacy" <mf...@verizon.net.INVALID>.
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
mflacy@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.