Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34024
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail |
|---|---|
| From | Popping mad <rainbow@colition.gov> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Why does Java argue about making a class instance |
| Date | Sat, 26 Mar 2016 19:44:53 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 57 |
| Message-ID | <nd6orl$k7m$1@reader1.panix.com> (permalink) |
| NNTP-Posting-Host | www.mrbrklyn.com |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | reader1.panix.com 1459021493 20726 96.57.23.82 (26 Mar 2016 19:44:53 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Sat, 26 Mar 2016 19:44:53 +0000 (UTC) |
| User-Agent | Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) |
| Xref | csiph.com comp.lang.java.programmer:34024 |
Show key headers only | View raw
When I try to compile this (example from antlr4 FIWIW)
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
ANTLRInputStream input = new ANTLRInputStream("y = 6*4 +
9 /8 / 2.5 + -3.21 * RUBEN; C = 5/9 * F + 32;");
CalcLexer lexer = new CalcLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
CalcParser parser = new CalcParser(tokens);
CollectVarsVisitor my_visitor = new CollectVarsVisitor();
// parser.prog();
ParseTree tree = parser.prog();
tree.accept(my_visitor);
System.out.println(my_visitor.vars);
}
public class CollectVarsVisitor extends CalcBaseVisitor<Void> {
HashSet<String> vars = new HashSet<String>();
@Override
public Void visitStmt(CalcParser.StmtContext ctx) {
TerminalNode id = ctx.ID();
if(id != null) {
vars.add(id.getText());
}
return super.visitStmt(ctx);
}
@Override
public Void visitExpr(CalcParser.ExprContext ctx) {
TerminalNode id = ctx.ID();
if(id != null) {
vars.add(id.getText());
}
return super.visitExpr(ctx);
}
}
}
it says
[ruben@manjaro calculator]$ javac Main.java
Main.java:15: error: non-static variable this cannot be referenced from a
static context
CollectVarsVisitor my_visitor = new CollectVarsVisitor();
^
1 error
I have no clue what is the problem, but it is not a standard static
problem
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Why does Java argue about making a class instance Popping mad <rainbow@colition.gov> - 2016-03-26 19:44 +0000
Re: Why does Java argue about making a class instance Joerg Meier <joergmmeier@arcor.de> - 2016-03-26 21:01 +0100
Re: Why does Java argue about making a class instance Popping mad <rainbow@colition.gov> - 2016-03-28 13:19 +0000
Re: Why does Java argue about making a class instance Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-28 14:59 -0400
Re: Why does Java argue about making a class instance Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-26 16:04 -0400
Re: Why does Java argue about making a class instance Popping mad <rainbow@colition.gov> - 2016-03-28 13:24 +0000
Re: Why does Java argue about making a class instance Arne Vajhøj <arne@vajhoej.dk> - 2016-03-28 09:50 -0400
Re: Why does Java argue about making a class instance Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-28 15:04 -0400
Re: Why does Java argue about making a class instance FredK <fred.l.kleinschmidt@gmail.com> - 2016-03-28 15:17 -0700
Re: Why does Java argue about making a class instance Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-28 18:30 -0400
Re: Why does Java argue about making a class instance Andreas Leitgeb <avl@logic.at> - 2016-03-26 20:17 +0000
Re: Why does Java argue about making a class instance Arne Vajhøj <arne@vajhoej.dk> - 2016-03-28 10:10 -0400
Re: Why does Java argue about making a class instance Roedy Green <inquiry@mindprod.com> - 2016-06-29 00:56 -0700
csiph-web