File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes loading a fellow class from a package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "loading a fellow class from a package" Watch "loading a fellow class from a package" New topic

loading a fellow class from a package

Chaz Andrews

Joined: Sep 20, 2005
Posts: 23
hello, I have two classes in a package called 'test'.
The first one is the servlet class, and the second one does some xml processing.
Currently when I go to include the xml class in the servlet i keep getting a cannot resolve symbol error.
I've tried
test.xmlclass x = new test.xmlclass();
xmlclass x = new test.xmlclass();
xmlclass x = new xmlclass();

what am I doing wrong?
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

have you import the package no top into your servelt..

cannot find Symbol: means you are using a class name that the compiler doesn't recognize or cannot find any resource to understand it.

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Chaz Andrews

Joined: Sep 20, 2005
Posts: 23
thanks for helping, If I understand you correctly, are you saying that in both the classes i should import the classes? I think I've tried that, this is what I've got:

package test;
import java.util.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.servlet.*;

import test.*;

public class theServlet extends HttpServlet {
test.xmlclass x = new test.xmlclass();


package test;

import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

import test.*;

public class xmlclass extends DefaultHandler{

That still doesnt work, im not sure i did what you suggested correctly tho.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

If both classes are in the same package (called 'test'), then the class files should be in the same directory (WEB-INF/classes/test if it's a web application), and you do not need to import anything.

Classes in the same package can access eachother directly, no importing needed, and you should just be able to do:

xmlclass x = new xmlclass();

in the servlet. Remove the line "import test.*" from your source files.
[ February 16, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: loading a fellow class from a package
jQuery in Action, 3rd edition