compilation problem

P

pete

i am currently studying exceptions within jsp and having a problem
compiling a class.... i have hit the errata discussion boards but
nothing was posted about this, so hopefully i can get the answer
here....

the following is my code straight out of my book, but it doesn't
compile... the goal is to utilize a custom Exception class called
UserException that i defined:

#################################

package com.wrox.errors;

public class ImprovedUser extends Object implements
java.io.Serializable{

public ImprovedUser() {};
private String username;
private String password;

public void setUsername(String name){
username = name;
}

public String getUsername(){
return username;
}

public void setPassword(String pass){
password = pass;
}

public void validateUser() throws Exception, NullPointerException{
if(username==null){
throw new UserException("Must supply a username!",null);}
if(password==null){
throw new UserException("Must supply a password!",username);}
if(!(username.equals("Casey") && password.equals("Kochmer"))){
throw new UserException("Couldn't validate password!",username);}
}
}

#################################

here are the errors i am getting; 3 of the same kind:

#################################

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch09\WEB-INF\classes\com\wrox\errors>javac
ImprovedUser.java
ImprovedUser.java:23: cannot resolve symbol
symbol : class UserException
location: class com.wrox.errors.ImprovedUser
throw new UserException("Must supply a username!",null);}
^
ImprovedUser.java:25: cannot resolve symbol
symbol : class UserException
location: class com.wrox.errors.ImprovedUser
throw new UserException("Must supply a password!",username);}
^
ImprovedUser.java:27: cannot resolve symbol
symbol : class UserException
location: class com.wrox.errors.ImprovedUser
throw new UserException("Couldn't validate password!",username);}
^
3 errors

#################################

please note that UserException.class is in the same directory as
ImprovedUser.java and that is in the errors directory mentioned in the
package reference at the top of the ImprovedUser.java file
above............

any help will be appreciated....

Thanks!

Pete
 
F

Fahd Shariff

You are compiling in the wrong directory.

You have to go to:
C:\jakarta-tomcat-5.0.28\webap­ps\begjsp-ch09\WEB-INF\classes­

and then compile using:
javac com/wrox/errors/*.java
 
P

pete

Fahd,

Thank you..... Your command worked.... But I am not clear on why it
worked.... Why couldn't I compile while in the errors directory as
so??

C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch09\WEB-INF\classes\com\wrox\errors>javac
ImprovedUser.java

I also tried to modify your command from

javac com\wrox\errors\*.java
(while here:
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch09\WEB-INF\classes)

to

javac com\wrox\errors\ImprovedUser.java
(while here:
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch09\WEB-INF\classes)

and that wouldn't work..... i get the same errors..... i do not know
why..... can you or someone else explain to me why these two don't
work:

javac ImprovedUser.java
(while here:
C:\jakarta-tomcat-5.0.28\webapps\begjsp-ch09\WEB-INF\classes\com\wrox\errors)
&
javac com\wrox\errors\ImprovedUser.java
(while here:
C:\jakarta-tomcat-5.0.28\webap­ps\begjsp-ch09\WEB-INF\classes)

yet this works:
javac com\wrox\errors\*.java
(while here:
C:\jakarta-tomcat-5.0.28\webap­ps\begjsp-ch09\WEB-INF\classes)

Thanks for everything!!!!!!

Pete
 
F

Fahd Shariff

Ok, lets first examine the errors. They are all of the kind:

ImprovedUser.java
ImprovedUser.java:23: cannot resolve symbol
symbol : class UserException
location: class com.wrox.errors.ImprovedUser

This means that the UserException class cannot be found, which implies
that this class does not lie on your classpath. Which package is this
class in? What is the full name of this class? Is it called
com.wrox.errors.UserException?

If you wish to compile the class from
C:\jakarta-tomcat-5.0.28\webap­ps\begjsp-ch09\WEB-INF\classes­\com\wrox\errors
you would have to explicitly tell the compiler where to look:

javac -classpath "%CLASSPATH%;..\..\.." ImprovedUser.java

But when you compile from the "root" i.e.
C:\jakarta-tomcat-5.0.28\webap­­ps\begjsp-ch09\WEB-INF\classe­s the
compiler would look in the current directory and would successfully
find com.wrox.errors.*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top