Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class not found Error

Status
Not open for further replies.

witchblade

Programmer
Aug 1, 2001
50
US
Can someone take a look at this code and tell me why I'm getting a "Class not found" error for "HideField" class?

//HTTP Session
//Working Copy
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HTTPSession extends HttpServlet
{

public static void displayProducts (ServletOutputStream out, HttpSession session)
throws IOException {
Vector books = (Vector) session.getValue ("books");
HideField h = new HideField();//prints all elements inside vector
//title = Quantity2 * COST2;
for (int i=0;i<books.size() ;i++ ) {
h = (HideField)books.elementAt(i);

out.println (&quot;<TR>&quot;);
out.println (&quot;<FORM method = \&quot;post\&quot; action=\&quot; out.println (&quot;<H3>&quot;);

out.println (&quot;<TD>&quot; +h.Title + &quot;</TD>&quot;);
out.println (&quot;<TD>&quot; +h.Author + &quot;</TD>&quot;);
out.println (&quot;<TD>&quot; +h.ISBN + &quot;</TD>&quot;);
out.println (&quot;<TD>&quot; + &quot;$&quot; + h.COST2 + &quot;</TD>&quot;);
out.println (&quot;<TD>&quot; + h.Quantity2 + &quot;</TD>&quot;);
out.println (&quot;<TD>&quot;);

out.println (&quot;<INPUT TYPE = \&quot;hidden\&quot; name=\&quot;ISBN\&quot; value=\&quot;&quot;+ h.ISBN+ &quot;\&quot;>&quot;);//inserts
out.println (&quot;<INPUT TYPE = \&quot;hidden\&quot; name=\&quot;action\&quot; value = \&quot;delete\&quot;>&quot;);

out.println (&quot;<INPUT TYPE = \&quot;submit\&quot; value = \&quot;REMOVE\&quot;\&quot;>&quot;);//remove button name
out.println (&quot;</TD>&quot;);
out.println (&quot;</TR></FORM>&quot;);

}//for
}//display

public void displayForm (ServletOutputStream out) throws IOException{
out.println(&quot;<FORM method = \&quot;Post\&quot;action =\&quot;}

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
//retrieves value assoc with parameter
//check if value or not
//creates the session object
HttpSession session = request.getSession(true);
response.setContentType(&quot;text/html&quot;);
ServletOutputStream out = response.getOutputStream();

if (session.isNew()){
//session.setMaxInactiveInterval(1000);//JDK version issues here
session.putValue (&quot;books&quot;, new Vector());//binds obj into session
}//end if

Vector b = (Vector) session.getValue (&quot;books&quot;);
if (request.getParameter(&quot;action&quot;).equals(&quot;delete&quot;))
{
String ISBN = request.getParameter (&quot;ISBN&quot;).trim();
removeItem(session, ISBN);//calls, removes method
}

else {
String Title = request.getParameter(&quot;Title&quot;);
String Author = request.getParameter(&quot;Author&quot;);
String ISBN = request.getParameter (&quot;ISBN&quot;);
String COST = request.getParameter (&quot;COST&quot;).trim();
String action = request.getParameter (&quot;action&quot;).trim();
String Quantity = request.getParameter (&quot;Quantity&quot;).trim();

Double COST2 = new Double(COST);
double c = COST2.doubleValue();
int qty = Integer.parseInt(Quantity);

Hidefield h = new HideField();//inserts all h elements inside vector

h.Title = Title;
h.Author = Author;
h.ISBN = ISBN;
h.COST2 = c;
h.Quantity = qty;
b.addElement(h);
}//else

//double total = (quantity2*cost2);
System.out.println (&quot;Hello here&quot;);

out.println (&quot;<H2><CENTER><FONT Color = 'maroon'>Book Nook Shopping Cart</FONT></CENTER></H2>&quot;);
out.println (&quot;<HTML><HEAD>&quot;);
out.println (&quot;</HEAD>&quot;);
out.println (&quot;<!--Primary Content-->&quot;);
out.println (&quot;<FORM name = \&quot;order\&quot; onsubmit=\&quot;return validate();\&quot; method =\&quot;Post\&quot; action = \&quot; out.println (&quot;<DIV align=\&quot;center\&quot;><IMG src=\&quot;/pileofbooks.jpg\&quot;&quot;);
out.println (&quot;</DIV>&quot;);

out.println(&quot;<TABLE border=1 width=100%>&quot;);
out.println(&quot;<TR>&quot;);
out.println(&quot;<TD width=25%>&quot;);
out.println(&quot;<H4><center>Title</center></H4>&quot;);
out.println(&quot;</TD>&quot;);
out.println(&quot;<TD width=25%>&quot;);
out.println(&quot;<H4><center>Author</center></H4>&quot;);
out.println(&quot;</TD>&quot;);
out.println(&quot;<TD width=25%>&quot;);
out.println(&quot;<H4><center>ISBN</center></H4>&quot;);
out.println(&quot;</TD>&quot;);
out.println(&quot;<TD width=25%>&quot;);
out.println(&quot;<H4><center>Cost</center></H4>&quot;);
out.println(&quot;</TD>&quot;);
out.println(&quot;<TD width=25%>&quot;);
out.println(&quot;<H4><center>Quantity</center></H4>&quot;);
out.println(&quot;</TD>&quot;);
out.println(&quot;<TD width=25%>&quot;);
out.println(&quot;<H4><center>Remove From Cart</center></H4>&quot;);
out.println(&quot;</TD>&quot;);
out.println(&quot;</TR>&quot;);

displayProducts(out,session);
out.println(&quot;</TABLE>&quot;);
out.println(&quot;</BODY>&quot;);
out.println(&quot;</HTML>&quot;);
out.flush();
out.close();
}//doGet


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
doGet(request, response);
}//doPost

public void removeItem (HttpSession session, String isbn){
System.out.println(&quot;in here&quot;);
HideField h;
Vector temp = (Vector)session.getValue (&quot;books&quot;);//gets back the whole vector
for (int i=0;i <=temp.size() ;i++ ){
h = (HideField)temp.elementAt(i);//get each object
System.out.println (h.ISBN +&quot;item removed&quot;+isbn);

if ((h.ISBN)equals(isbn))//checks for match
{
System.out.println(&quot;item removed&quot;);
temp.removeElementAt(i);//removes if there is a match
}//end if
}//end for
session.putValue (&quot;books&quot;, temp);//puts vector back in session
}//end remove item
}//class HttpSession


HTTPSession.java:14: Class HideField not found.
HideField h = new HideField();//prints all elements inside vector
 
I do not think there is anything wrong with your code. Javac cannot find a class named HideField anywhere in the classpath.

Assuming HideField is a class that has no package definition and is in the same directory as HTTPSession, then it is possible that that directory is not in the classpath. It is often useful to have the first entry of your classpath as '.'.

set classpath=.;c:\java\lib\servlet.jar

This lets Java use all the classes you probably need.

Also, there is a line in your code...

Hidefield h = new HideField();//inserts all h elements inside vector

... that has a Hidefield where it may be ment to be HideField, but I do not think that is your current problem.

I could be way off here, so if this is no use please state what directory HideField is in, if it has any package definition and what your classpath is.

 
right on for placing the current directory in your classpath.

Also make sure the jar containing your class is part of your classpath, not just the directory where the jar is!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top