Results 1 to 7 of 7
Thread: Why isnt java.io being used ?
- 11-28-2012, 03:07 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
Why isnt java.io being used ?
I am using import.java.io.*; at the beginning of my code so that I can write my own exceptions. However, after compiling my program, I am getting a warming claiming that java.io is not being used. When running the Remove() method in my Tester class, I get unhandled exception errors. Any insight? TIA
Here are the static classes I wrote to create the methods:
And here is the method that I want to throw them in:Java Code:public static class ListEmptyException extends Exception { public ListEmptyException(String s) {super (s);} } public static class NotInListException extends Exception { public NotInListException(String s) {super (s);} }
Java Code:public void remove(Comparable d) throws ListEmptyException, NotInListException{ Node<Comparable> previous, traverse; if(empty()) throw new ListEmptyException("empty when removed"); previous = head; traverse = head.next; while(traverse != null && !traverse.data.equals(d)) { previous = traverse; traverse = traverse.next; } if(traverse == null) throw new NotInListException("Item is not in the list"); if(previous == null) { traverse = traverse.next; } else { previous.next = traverse.next; size--; } }
-
Re: Why isnt java.io being used ?
Why do you think that java.io.*; should be used? What io classes do you think that you are using in your code?
- 11-28-2012, 03:32 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
- 11-28-2012, 03:34 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
Re: Why isnt java.io being used ?
here is the code in the main of my Tester class, if it makes a difference..
Java Code:try { numbers.remove(10); } catch (ListEmptyException e) { System.out.println(e.getMessage() +"OK: The list is empty"); } catch (NotInListException e) { System.out.println("WRONG: This should not happen"); }
-
Re: Why isnt java.io being used ?
- 11-28-2012, 03:50 PM #6
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
Re: Why isnt java.io being used ?
This is pretty much exactly how it was shown to us in notes, and the Tester class was provided to us. Are my static classes correct? What needs to be changed?
-
Re: Why isnt java.io being used ?
What happens when you test your code with code that should result in the exceptions being thrown? Does it work as expected? What about when you use code that should work well? Does the code still work as expected? One proof of its validity (admittedly only a partial proof) is in its functioning.
Similar Threads
-
Not sure why my code isnt working
By MutatedGamers in forum New To JavaReplies: 2Last Post: 11-20-2012, 09:27 PM -
JLayeredPane isnt displaying
By rasen58 in forum Java AppletsReplies: 1Last Post: 11-01-2012, 04:20 PM -
Omg! Towers of Hanoi. Seriously. Why isnt this right?
By Meta in forum New To JavaReplies: 5Last Post: 04-28-2010, 04:42 PM -
Why isnt this working?
By GoingThroAPhase in forum New To JavaReplies: 4Last Post: 04-03-2010, 02:36 AM -
why isnt it sending value
By snitdesne in forum New To JavaReplies: 5Last Post: 10-24-2008, 07:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks