This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loading a fellow class from a package

 
Chaz Andrews
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1324
Android Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chaz Andrews
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic