I’m trying to compile this program in Netbeans: Lab1.java
And I get this error…
BF.java:27: non-static variable this cannot be referenced from a static context
return new Program(new BF().doParse(str));
I’ve tried everything!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your Program inner class is not declared static. What this means is that a Program instance can only live inside an enclosing instance of the outer BF class. If you want the Program class to exist independently, so that you can write
new BF.Program()you have to declare itstatic.In your program, you’re creating a new instance of Program in the main method in a static context without an enclosing BF instance, which is illegal. Just add static to the program class declaration.