This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Throws clause throws compile error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Throws clause throws compile error" Watch "Throws clause throws compile error" New topic
Author

Throws clause throws compile error

Bacon
Ranch Hand

Joined: Jul 14, 2004
Posts: 305
Here is part of a sample program I'm trying to compile.

public void setSTATE (String state) throws InvalidStateException {
String states[] = {"AL","AL","AZ","AR","CA","CO","CT",
"CE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA",
"ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH",
"NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC",
"SD","TN","TX","UT","VT","VA","WA","DC","WV","WI","WY"};
if (state.length() != 2)
throw new InvalidStateException(state);
for (int i=0; i<states.length;i++) {
if (state.equals(states[i])) {
STATE = state;
return;
}
}
throw new InvalidStateException(state);
}

Upon compile I get this error.

Customer.java:193: cannot resolve symbol
symbol : class InvalidStateException
location: class Customer.Customer
public void setSTATE (String state) throws InvalidStateException {

The "catch" is defined in the main function:

public static void main (String[] args) {
Customer cust = new Customer(new BigDecimal("2"));
cust.print();
try {
cust.setSTATE("ZL");
} catch (InvalidStateException err) {}
try {
cust.setSTATE("MA");
} catch (InvalidStateException err) {}

What am I missing?

Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

Originally posted by Ray Marsh:


What am I missing?

Thanks


A class named "InvalidStateException".


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Robert Konigsberg
Ranch Hand

Joined: Jun 23, 2004
Posts: 172
Hey, where in your list of states is DC, Puerto Rico, Guam and other postal abbreviations?


SCJP 1.4 (91%)<br />SCJD 1.4 (376/400, 94%)
Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi,
I think you forget to import InvalidStateException Class in your source code....

kalai Selvan T.
Bacon
Ranch Hand

Joined: Jul 14, 2004
Posts: 305
Thank you. I wasn't sure how the InvalidStateException was supposed to be defined.

The InvalidStateException class must be else where in the code. I'll try to find it.

This is not my code, it is a sample from a book.
Bacon
Ranch Hand

Joined: Jul 14, 2004
Posts: 305
Got it. Thank you.
 
jQuery in Action, 2nd edition
 
subject: Throws clause throws compile error
 
Similar Threads
Reg. Exception hierarchy
throw
unable to run restful webserive
Exception doubt
Getting a class name without an instantiated object