1

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!

Asaph
  • 159,146
  • 25
  • 197
  • 199
TheFrack
  • 2,823
  • 7
  • 28
  • 47
  • Please copy/paste the relevant code snippets into your question. Also please be sure to use the "Homework" tag if this is a question about homework. – Ben Burns May 30 '11 at 03:30
  • 1
    BTW: The file can't be called `Lab1.java` if you want to actually compile this program. It would have to be called `BF.java`. – Asaph May 30 '11 at 03:35

3 Answers3

2

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 it static.

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.

Steve B.
  • 55,454
  • 12
  • 93
  • 132
1

Change line 171 from:

class Program implements Node

to this:

static class Program implements Node
Asaph
  • 159,146
  • 25
  • 197
  • 199
0

Non-static variable cannot be referenced from a static context

Community
  • 1
  • 1
Siva Arunachalam
  • 7,582
  • 15
  • 79
  • 132