Results 1 to 4 of 4
  1. #1
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

    Default javac - cannot find symbol

    Hi all, I have this file structure:
    Java Code:
    src/test/HtmlFactory.java
    src/test/IndexPage.java
    inside the first file I wrote this code
    Java Code:
    package test;
    
    public class HtmlFactory {
    	public static final String DOCTYPE =
    	    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
    		"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\t\t\t" +
            "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n";
            
    	public static String head(String title) {
    	    String html = "";
    	    html += DOCTYPE;
    	    html += "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
    		    html += "\t<head>\n";
    				html += "\t\t<title>" + title + "</title>\n";
    		    html += "\t</head>\n";
    		    
    		return html;
    	}
    }
    and inside the second file is following
    Java Code:
    package test;
    
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class IndexPage extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
    	
    	String html = HtmlFactory.head("Index page");
    	html += "\t<body>\n";
    	html += "\t\t<h1>Hi, I'm John</h1>\n";
    	html += "\t</body>\n";
    	html += "</html>";
    
    	out.println(html);
      }
    }
    Now I need to make .class files. I'm inside test directory and in command line I call
    Java Code:
    "C:\Program Files\Java\jdk1.6.0_17\bin\javac.exe" HtmlFactory.java
    and everything pass (class was made). But when I call
    Java Code:
    "C:\Program Files\Java\jdk1.6.0_17\bin\javac.exe" IndexPage.java
    command line returns following
    Java Code:
    IndexPage.java:12: cannot find symbol
    symbol: variable HtmlFactory
    location: class test.IndexPage
            String html = HtmlFactory.head("Index page");
                          ^
    1 error
    Can you help me pls. Thnx

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,772
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by BigBear View Post
    Hi all, I have this file structure:
    Java Code:
    src/test/HtmlFactory.java
    src/test/IndexPage.java
    inside the first file I wrote this code
    Java Code:
    package test;
    ...
    Now I need to make .class files. I'm inside test directory and in command line I call
    Java Code:
    "C:\Program Files\Java\jdk1.6.0_17\bin\javac.exe" HtmlFactory.java
    and everything pass (class was made). But when I call
    Java Code:
    "C:\Program Files\Java\jdk1.6.0_17\bin\javac.exe" IndexPage.java
    command line returns following
    Java Code:
    IndexPage.java:12: cannot find symbol
    symbol: variable HtmlFactory
    location: class test.IndexPage
            String html = HtmlFactory.head("Index page");
                          ^
    1 error
    Can you help me pls. Thnx
    Both of these classes are stored in a package named 'test' so their complete (the term for this is: 'fully qualified') names is test.HtmlFactory and test.IndexPage, and should be stored in a directory that mirrors their name, i.e. in the directory test/<classname>.class.

    The parent directory of that test directory should be part of the classpath variable and you can run those classes by supplying their fully qualified names; e.g.

    Java Code:
    java -cp <parent of test directory> test.IndexPage
    kind regards,

    Jos

  3. #3
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

    Default

    ok, thnx very much

  4. #4
    852000 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    you also can set the enviorenment variable:classpath to the src directory

Similar Threads

  1. Can not find symbol ???
    By AliceNewbie in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 02:44 AM
  2. javac can't find javax.ejb...
    By qrac in forum New To Java
    Replies: 3
    Last Post: 07-30-2009, 08:13 PM
  3. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  4. cannot resolve symbol while using javac
    By andi9 in forum New To Java
    Replies: 5
    Last Post: 05-14-2008, 07:50 AM
  5. Replies: 3
    Last Post: 05-01-2008, 09:30 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
  •