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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Package compile error "cannot resolve symbol"

Status
Not open for further replies.

cgreynes

Programmer
Feb 28, 2003
29
US
Hi,

When I compile the .java file from the book, I get a "cannot resolve symbol". It point to the bean file.

BankCustomer.java
------------------------------
package coreservlets;

import java.util.*;

public class BankCustomer {
private String id, firstName, lastName;
private double balance;

public BankCustomer(String id, String firstName, String lastName, double balance) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.balance = balance;
}

public String getId() {
return(id);
}

public String getFirstName() {
return(firstName);
}

public String getLastName() {
return(lastName);
}

public double getBalance() {
return(balance);
}

public double getBalanceNoSign() {
return(Math.abs(balance));
}

public void setBalance(double balance) {
this.balance = balance;
}

private static HashMap customers;

static {
customers = new HashMap();
customers.put("id001", new BankCustomer("id001", "John", "Hacker", -3456.78));
customers.put("id002", new BankCustomer("id002", "Jane", "Hacker", 1234.56));
customers.put("id003", new BankCustomer("id003", "Juan", "Hacker", 987654.32));
}

public static BankCustomer getCustomer(String id) {
return((BankCustomer)customers.get(id));
}
}
------------------------------

ShowBalance.java

------------------------------
package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ShowBalance extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
BankCustomer customer = BankCustomer.getCustomer(request.getParameter("id")); //error out when using BankCustomer
String address;
if (customer == null) {
address = "/WEB-INF/bank-account/UnknownCustomer.jsp";
} else if (customer.getBalance() < 0) {
address = "/WEB-INF/bank-account/NegativeBalance.jsp";
request.setAttribute("badCustomer", customer);
} else if (customer.getBalance() < 10000) {
address = "/WEB-INF/bank-account/NormalBalance.jsp";
request.setAttribute("regularCustomer", customer);
} else {
address = "/WEB-INF/bank-account/HighBalance.jsp";
request.setAttribute("eliteCustomer", customer);
}
RequestDispatcher dispatcher =
request.getRequestDispatcher(address);
dispatcher.forward(request, response);
}
}
------------------------------

Thanks and I am sorry if this is a simple error. I tried to set the ClassPath and still did not work. I am using Apache Tomcat 5.5.


Clark
 
when I type
"...\javac ShowBalance.java"

the error below shows up...
----------------------------------------------
ShowBalance.java:11: cannot resolve symbol
symbol : class BankCustomer
location: class coreservlets.ShowBalance
BankCustomer customer = BankCustomer.getCustomer(request,getParameter("id"));
^
ShowBalance.java:11: cannot resolve symbol
symbol : variable BankCustomer
location: class coreservlets.ShowBalance
BankCustomer customer = BankCustomer.getCustomer(request,getParameter("id"));
^

2 errors
----------------------------------------------



 
The second error is pointing to the second BankCustomer (not customer variable).
 
You have two problems - you have probably not set your CLASSPATH correctly, and also you are not comiling the class correctly.

If your .java file is in "/usr/java/coreservlets/ShowBalance.java"

then you need to change directory to "/usr/java" and then type :

javac coreservlets/ShowBalance.java

But you must also set your CLASSPATH to "/usr/java" so that the other classes in the coreservlets package/directory are found by the compiler.

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks sedj. I can compile the code.

I set the class path to:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\bluereef\WEB-INF\classes>

where coreservlets directory is under classes directory.

and compiled using your command javac coresrvlets/ShowBalance.java
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top