I'm new to Java and I've looked around the web for solutions but none seem to work. Please help me.
I have two files. One of them is the java file that contains the main function. In it:
...
VaporVisitor visitor = new VaporVisitor();
...
With that command, I want to create a new object VaporVisitor
, which is a class in a separate file called VaporVisitor.java
. However Java doesn't recognize what VaporVisitor is, presumably because it doesn't know VaporVisitor.java
exists (it's in the same directory). I tried making them part of the same package, in different packages and importing...and all of them failed. Can anyone give me any guidance?
Thanks!
EDIT: Here's exactly what I'm doing, and the error message I get: So I have 3 files. V2VM (with my main function), VaporVisitor, and a provided jar file that has several custom classes. The jar file isn't giving me any problems; it's trying to get java to recognize VaporVisitor.
So in V2VM (the main function), I've tried putting in: import V2VM.java;
which didn't work. I've tried putting V2VM in a subfolder called vv, added package vv;
to VaporVisitor and put in V2VM.java import vv.*
but that didn't work either.
For compiling, I tried javac -classpath [the jar file].jar V2VM.java
The errors it gives me:
V2VM.java:15: cannot find symbol
symbol : class VaporVisitor
location: class V2VM
VaporVisitor visitor = new VaporVisitor();
^
V2VM.java:15: cannot find symbol
symbol : class VaporVisitor
location: class V2VM
VaporVisitor visitor = new VaporVisitor();
^
When I run javacc
I am in the same directory as V2VM, which is also where the other two files are located. I've tried putting V2VM and VaporVisitor in the same package, but that didn't work either. So they are not part of any package now...
EDIT 2: SOURCE CODE OF VaporVisitor and V2VM
V2VM.java:
package vv; //whether I put this or not, it doesn't work
//this stuff was provided, and is related to importing contents of the jar file; don't think this is the problem
import cs132.util.ProblemException;
import cs132.vapor.parser.VaporParser;
import cs132.vapor.ast.VaporProgram;
import cs132.vapor.ast.VBuiltIn.Op;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import vv.VaporVisitor; //whether I put this or not, it doesn't work
public class V2VM{
public static void main(String [] args){
VaporProgram vp = parseVapor(System.in, System.err);
VaporVisitor visitor = new VaporVisitor();
for(int i=0; i<vp.functions.length; i++){
for(int j=0; j<vp.functions[i].body.length; j++){
vp.functions[i].body[j].accept(parameter, visitor);
}
}
}
public static VaporProgram parseVapor(InputStream in, PrintStream err){
...
}
For VaporVisitor.java:
package vv;
public class VaporVisitor extends VInstr.VisitorPR<Parameter_Type, Return_Type, RuntimeException>{
....
}
All 3 files are in the same directory vv