aspose file tools*
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
Author

loading a fellow class from a package

Chaz Andrews
Greenhorn

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();
and
xmlclass x = new test.xmlclass();
and
xmlclass x = new xmlclass();

what am I doing wrong?
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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.


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

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.io.*;
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();

And:

package test;
import java.io.*;
import java.net.*;

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: 14150
    
  18

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 7 API documentation
Scala Notes - My blog about Scala
 
Don't get me started about those stupid light bulbs.
 
subject: loading a fellow class from a package