This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

attributes and listeners HF p171-176  RSS feed

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I created the 3 class files for the tutorial on those pages. Source code for all three classes exist in MyProjects\listenerTest\src\com\example\

All three java files (MyServletContextListener.java, Dog.java, ListenerTester.java) exist in the above directory.

I can successfully compile Dog.java but when I try to compile either of the other two I get:

java:24 cannot find symbol
symbol: class dog

HF is not clear about where to put the src code for this tutorial so I assumed it should be in a similiar directory structure as beerV1 with the exception of both model and web.

I did verify that each .java file has the exact same package com.example; statement in it.

When I compile Dog.java the .class file is located in the same directory as the .java file - I do not re-direct the output.

I suspect my error lays somewhere in the directory/package structure but cannot find it.

Any help is greatly appreciated.

Thanks,

Jerry Bustamente
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class dog(Shouldn't it be [D]og)

Can that be the problem? Check the package structure again. Post the source code so that the forum can cross-check your source code.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

java:24 cannot find symbol
symbol: class dog

this error means that your other files are not able to find the dog class
did you try adding it to the class path
try this

C:\myprojects\beer\src>javac -classpath "c:\Program Files\Apache Group\Tomcat 4.
1\common\lib\servlet.jar";..\classes -d ..\classes com\example\web\dogservlet.ja
va


ie add your dog.class to the classpath
this works
regards
priya
 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for responding so quickly. :-)

Still having problem.

I double checked the "d" in dog and it is correctly spelled as Dog. Good to check though. Thanks.

Below is the source code for the 3 classes.

all 3 files are located in

C:\MyProjects\ListenerTest\classes/com/example

classpath looks like .;C:\MyProjects\beerV1\classes;C:\MyProjects\ListenerTest\classes;...

public class Dog {

private String breed;

public Dog (String breed) {

this.breed = breed;
}

public String getBreed() {

return breed;
}
}

package com.example;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

public class ListenerTester extends HttpServlet {

public void doGet (HttpServletRequest request,
HttpServletResponse response)

throws IOException, ServletException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("test context attributes set by listener<br>");

out.println("<br>");

Dog dog = (Dog) getServletContext().getAttribute("dog");

out.println("Dog's breed is: " + dog.getBreed());

}

}

package com.example;

import javax.servlet.*;

public class MyServletContextListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent event) {

ServletContext sc = event.getServletContext();

String dogBreed = sc.getInitParameter("breed");

Dog d = new Dog(dogBreed);

sc.setAttribute("dog", d);

}

public void contextDestroyed(ServletContextEvent event) {

// nothing to do here

}

}


Your help is appreciated.

Jerry Bustamente
 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the files to compile by first compiling Dog.java then putting the Dog.class file in C:\MyProjects\beerV1\classes\com\example

Then I moved the other two files to that folder and successfully there which placed the class files also in that directory.

To compile I changed directory to the above directory then executed a simple javac ... command.

What this tells me is that the CLASSPATH (which I changed to eliminate MyProjects\ListenerTest... and just use the beerV1 directory structure.

So, since my classpath has C:\MyProjects\beerV1\classes in it any subsequent compiles which need the Dog.class need to have their .java file also in the

C:\MyProjects\beerV1\classes\com\example directory.

Thanks for your assistance.

Sincerely,

Jerry Bustamente
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!