Results 1 to 7 of 7
  1. #1
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default 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:

    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);}
      }
    And here is the method that I want to throw them in:

    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--;
        }
      }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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?

  3. #3
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default Re: Why isnt java.io being used ?

    Quote Originally Posted by Fubarable View Post
    Why do you think that java.io.*; should be used? What io classes do you think that you are using in your code?
    dont I need java.io to create and throw exceptions?

  4. #4
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default 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");
      }

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why isnt java.io being used ?

    Quote Originally Posted by bdl1127 View Post
    dont I need java.io to create and throw exceptions?
    Have you first looked at the API for the Exception and the Throwable classes to see what is required for their use? It's all there in the API. See if they are declared as java.io.Exception and java.io.Throwable? They're not.

  6. #6
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default 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?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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

  1. Not sure why my code isnt working
    By MutatedGamers in forum New To Java
    Replies: 2
    Last Post: 11-20-2012, 09:27 PM
  2. JLayeredPane isnt displaying
    By rasen58 in forum Java Applets
    Replies: 1
    Last Post: 11-01-2012, 04:20 PM
  3. Replies: 5
    Last Post: 04-28-2010, 04:42 PM
  4. Why isnt this working?
    By GoingThroAPhase in forum New To Java
    Replies: 4
    Last Post: 04-03-2010, 02:36 AM
  5. why isnt it sending value
    By snitdesne in forum New To Java
    Replies: 5
    Last Post: 10-24-2008, 07:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •