Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:59:53+00:00 2026-06-15T04:59:53+00:00

I’m new to Java and I’ve looked around the web for solutions but none

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:59:54+00:00Added an answer on June 15, 2026 at 4:59 am

    OK. So first of all, you never refer to a class in Java by appending .java to its name. Second: in order to compile a class A that uses another class B, the class B must be compiled, and available in the classpath. Or you must compile both A and B at the same time.

    So, you should have the following structure:

    project
       lib
          someFile.jar
       src
          vv
             V2VM.java
             VaporVisitor.java
       classes
    

    Both classes should start with:

     package vv;
    

    There’s no need to import V2VM in VaporVisitor or vice versa, since they are in the same package.

    To compile the files, you should be in the project directory, and use the following command:

    javac -cp lib/someFile.jar -d classes src/vv/V2VM.java src/vv/VaporVisitor.java
    

    This will compile the two files at once, and put their compiled class files in project/classes:

    project
       classes
          vv
             V2VM.class
             VaporVisitor.class
    

    You put the jar file in the classpath because the classes you compile use classes from this jar file.

    Then, to run your class, you need to have both the jar file, and the classes directory in the classpath. And the fully qualified name of the main class is vv.V2VM. So the command is

    java -cp lib/someFile.jar:classes vv.V2VM
    

    If you’re on windows, you must use \ instead of /, and ; instead of :.

    If you wanted to compile VaporVisiotr first, and then V2VM, you could. But then you would have to do the following:

    javac -cp lib/someFile.jar -d classes src/vv/VaporVisitor.java
    

    This compiles VaporVisiotr only, and put its class file in project/classes. Then you need to compile V2VM, which depends on VaporVisitor. So the compiled VaporVisitor class must be available in the classpath. So the command is

    javac -cp lib/someFile.jar:classes -d classes src/vv/V2VM.java
    

    If you decided to put VaporVisitor in another package (vv.foo for example), then you would need the following structure:

    project
       lib
          someFile.jar
       src
          vv
             V2VM.java
             foo
                 VaporVisitor.java
       classes
    

    The VaporVisitor.java would need to start with

    package vv.foo;
    

    And the V2VM.java file would need to have

    package vv;
    import vv.foo.VaporVisitor;
    

    Read the tutorial about packages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.