aspose file tools*
The moose likes Beginning Java and the fly likes Package Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package Problem" Watch "Package Problem" New topic
Author

Package Problem

Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
Hello!

When i am trying to access an object of a class in another class which is in same package i am getting the following error.....

D:\PROJECT\LISTEN>javac -d classes/com/example src/com/example/MyServletContextL
istener.java
src/com/example/MyServletContextListener.java:13: cannot find symbol
symbol : class Dog
location: class com.example.MyServletContextListener
Dog d = new Dog(dogBreed);
^
src/com/example/MyServletContextListener.java:13: cannot find symbol
symbol : class Dog
location: class com.example.MyServletContextListener
Dog d = new Dog(dogBreed);
^
2 errors

---------------------------------------------------------------------------

this dog class is in same package. What is the problem? Please help.


Mission SCWCD. Mission SCJP Complete: SCJP 1.4 - 91%
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When you specify a directory for the compiled objects, you should not include the directories that are part of the package name. In your example you should simply write -d classes instead of -d classes/com/example.

Also, if you're not compiling all the classes in the package together (e.g. src/com/example/*.java), then you have to include the destination directory in your classpath. Example: -cp classes;%classpath%
[ May 12, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
i trying compiling like this...

javac -d classes src/com/example/MyServletContextListener.java

here is the file.......of MyServletContextListener.java

package com.example;

import javax.servlet.*;
import javax.servlet.http.*;

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
}
}

now......i am getting an error......
src/com/example/MyServletContextListener.java:13: cannot find symbol
symbol : class Dog
location: class com.example.MyServletContextListener
Dog d = new Dog(dogBreed);
^
src/com/example/MyServletContextListener.java:13: cannot find symbol
symbol : class Dog
location: class com.example.MyServletContextListener
Dog d = new Dog(dogBreed);
^
2 errors

--------------

here is the Dog.java file which is in same package......please tell me what should i do so that it can access the dog class??!!

package com.example;

public class Dog
{
private String breed;
public Dog(String name)
{
this.breed = breed;
}

public String getBreed()
{
return breed;
}

}


Thanks for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package Problem