2 Replies - 24667 Views - Last Post: 23 March 2006 - 02:43 PM Rate Topic: -----

#1 rhebert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-March 06

"cannot find symbol" error

Posted 21 March 2006 - 08:29 PM

I'm trying to create a servlet that creates and uses a list of objects of class Site, which I've created and compiled myself. I keep getting a "cannot find symbol" error when I attempt to compile. Assumed this was a classpath problem, but I tried several things there and it still didn't seem to work. Any suggestions would be most appreciated. Servlet code looks roughly like this (uses a few functions from the Google Maps API - I've used (...) to abbreviate some lines that shouldn't be relevant):

package mypackage;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public final class Map extends HttpServlet {

   List<Site> aList = new ArrayList<Site>(2);
   Site a = new Site("Residence", -74.001634, 40.732889);
   Site b = new Site("Residence", -74.003161, 40.732889);
   
 

   public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
      throws IOException, ServletException {

	aList.add(0, a);
       aList.add(1, b);

	response.setContentType("text/html");


	PrintWriter writer = response.getWriter();

	writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
	
       ...

	writer.println("function createMarker(point, number) {");
	writer.println("var marker = new GMarker(point);");

	writer.println("GEvent.addListener(marker, 'click', function() {");
	writer.println("marker.openInfoWindowHtml(html);");
	writer.println("});");
	writer.println("return marker;");
	writer.println("}");
	writer.println("for (var i = 0; i < aList.length - 1; i++) {");
	writer.println("var point = new GPoint(aList.get(i).lon, aList.get(i).lat);");
	writer.println("var marker = createMarker(point, i + 1);");
	writer.println("map.addOverlay(marker);");
	writer.println("}");
	writer.println("</script>");
	writer.println("</body>");
	writer.println("</html>");


    }


}



classpath looks like this: :/usr/local/tomcat/webapps/test/WEB-INF/servlet-api.jar:/usr/local/tomcat/webapps/test/WEB-INF/classes/mypackage/:/usr/local/tomcat/webapps/test/WEB-INF/classes/mypackage/*

And the error I'm getting is this:

src/mypackage/Map.java:14: cannot find symbol
symbol : class Site
location: class mypackage.Map
List<Site> aList = new ArrayList<Site>(2);
^
src/mypackage/Map.java:15: cannot find symbol
symbol : class Site
location: class mypackage.Map
Site a = new Site("Residence", -74.001634, 40.732889);

etc., etc..... Any ideas? Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: "cannot find symbol" error

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: "cannot find symbol" error

Posted 21 March 2006 - 11:22 PM

Well first problem I see is you are not creating an ArrayList correctly.

Here is a link to the API. Just look up ArrayList to see how to utilize it. Unless you are storing a collection inside which takes a different set of parameters in its constructor.

This is what it should be:

List aList = new ArrayList(2);



As for these errors:

Quote

src/mypackage/Map.java:15: cannot find symbol
symbol : class Site
location: class mypackage.Map
Site a = new Site("Residence", -74.001634, 40.732889);


Do you have the Site.class file in the same folder as the Map.class file??
Was This Post Helpful? 0
  • +
  • -

#3 jstephens  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 214
  • Joined: 07-November 05

Re: "cannot find symbol" error

Posted 23 March 2006 - 02:43 PM

I have had this problem a couple of times. The first time I found it to be a spelling mistake. The other time was that the classes where not in the same directory. The third time was that I didn't import the right package which would lead back to it really being the same as the second time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1