Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Cannot compile public class

    Hello!

    I'm having a problem compiling a class called Starter using javac which contains the main and takes arguments from command-line. I have a package ssb402 containing the following files

    Starter
    InputReader
    FirstPass
    SecondPass
    ErrorHandler

    The Starter class instantiates the other classes and uses their functions. (e.g. InputReader ir = new InputReader(); ip.setFileData(); )

    When I compile my non-main classes, I get no error. But only when I compile my Starter class, I get an error saying

    C:\Users\Shobit Beltangdy\Desktop\testin\ssb402\Starter.java:23: error: cannot f
    ind symbol
    ErrorHandler errorHandler = new ErrorHandler();
    ^
    symbol: class ErrorHandler
    location: class Starter
    C:\Users\Shobit Beltangdy\Desktop\testin\ssb402\Starter.java:23: error: cannot f
    ind symbol
    ErrorHandler errorHandler = new ErrorHandler();


    for all the non-main classes.

    What could be the reason? Is it some problem with directory structure? But then why are the other classes compiling?

    Please help!

    Thanks!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot compile public class

    You may need to show us some code, especially the Starter file. If you do, please use code tags where you place the tag [code] above your code block and [/code] below your code block (note the square brackets and the difference between the top and bottom tag) like so:

    [code]
    Your code block goes here
    [/code]

    This helps your code retain its formatting.

    Also post the actual error message themselves again in code tags.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,887
    Rep Power
    25

    Default Re: Cannot compile public class

    I have a package ssb402
    If your classes are in a package the classpath must point to the folder with the start of the package.
    Does the classpath point to the folder containing the ssb402 folder when you try to compile?

  4. #4
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Cannot compile public class

    Thanks for the prompt reply! So to give you some more details, I've made the project in EclipseIndigo, so the project is in C:/Users/Shobit Beltangdy/workspace/Lnkr/ssb402

    Now I'm trying to send the project across to my supervisor and so I thought of sending him the .java files (because he wants to compile them himself). So I tried doing it myself (by storing the .java files on a desktop folder) and tried compiling as follows:

    javac C:/Users/Shobit Beltangdy/Desktop/Link/ErrorHandler.java
    <no error>
    javac C:/Users/Shobit Beltangdy/Desktop/Link/InputReader.java
    <no error>
    etc.

    My Starter class looks like this:
    Java Code:
    public class Starter {
    
    
    	public static void main(String[] args) {
    			
    			String filePath = args[0];
    			
    			InputReader inputReader = new InputReader();
    			FirstPass firstPass = new FirstPass();
    			SecondPass secondPass = new SecondPass();
    			ErrorHandler errorHandler = new ErrorHandler();
    
                            inputReader.setFileData(filePath);	
    			inputReader.setNoOfLines(inputReader.getFileData());
    			inputReader.setNoOfModules(inputReader.getNoOfLines());
    
    			System.out.println("No of Lines "+inputReader.getNoOfLines());
    			System.out.println("No of Modules "+inputReader.getNoOfModules());
    			
    			boolean flag1 = errorHandler.isMultiplyDefined(inputReader.getFileData(), inputReader.getNoOfLines());
    			boolean flag2 = errorHandler.isUsedNotDefined(inputReader.getFileData(), inputReader.getNoOfLines());
    			boolean flag3 = errorHandler.definitionAddressExceedsSizeOfModule(inputReader.getFileData(), inputReader.getNoOfLines());
    			errorHandler.isDefinedNotUsed(inputReader.getFileData(), inputReader.getNoOfLines());
    			errorHandler.isNotUsedActually(inputReader.getFileData(), inputReader.getNoOfLines());
    			
    			if(flag1||flag2||flag3)
    				System.exit(0);
    			
    			firstPass.setModuleBaseAddress(inputReader.getFileData(),inputReader.getNoOfLines());
    			firstPass.setSymbolTable(inputReader.getFileData(), inputReader.getNoOfLines());
    			
    			secondPass.setNoOfVarPerMod(inputReader.getFileData(),inputReader.getNoOfLines());
    			secondPass.setModuleSize(inputReader.getFileData(), inputReader.getNoOfLines());
    			boolean flag4 = secondPass.setMemoryMap(inputReader.getFileData(), inputReader.getNoOfLines(), inputReader.getNoOfModules(), firstPass.getModuleBaseAddress(),firstPass.getSymbolTable());
    			if(flag4)
    				System.exit(0);
    			
    	}
    Also, I'm not sure what you mean by 'pointing the classpath to the folder ssb402'. Do you mean I should write the location of the folder when I write javac like this -> javac <location/file.java>. That's what I did, and that's how the other non-main classes get compiled, but not the Starter.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,887
    Rep Power
    25

    Default Re: Cannot compile public class

    I don't know if your IDE will set the classpath.
    pointing the classpath to the folder ssb402
    That's not exactly what I said: classpath point to the folder containing the ssb402 folder
    Say the path was: C:\test\ssb402
    then the classpath should be: C:\test
    the test folder contains the ssb402 folder

    Your Starter class code that you posted shows that the class is not in a package.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot compile public class

    I think the best thing is to export your code by making a jar file, and Eclipse will do most of this for you. What I suggest you do is:

    • Go to the File menu
    • Export
    • Java
    • Jar File then Next
    • Select the files that you want to include
    • Make sure to select the Export Java source files and resources checkbox.


    Then send him the jar'd file.

Similar Threads

  1. Public class problem
    By glitchdetector in forum New To Java
    Replies: 3
    Last Post: 02-22-2011, 11:43 PM
  2. public class error
    By _inase in forum New To Java
    Replies: 2
    Last Post: 01-25-2011, 06:49 AM
  3. Public, private or (nothing) class
    By tyang in forum New To Java
    Replies: 3
    Last Post: 02-01-2010, 12:37 AM
  4. different multiple public class and main class
    By mr idiot in forum New To Java
    Replies: 2
    Last Post: 01-01-2009, 01:10 PM
  5. Public class variable
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •