Himura Kenshin Posted September 30, 2004 Report Posted September 30, 2004 Need help with a program heres what i get in command prompt: Animals.java:9: unreported exception java.io.IOException; must be caught or declared to be thrownDogman(); ^ Heres my code : import java.io.*; public class Animals{public static void main(String[] args){ Dogman();System.out.println("Animal List");} public static void Dogman() throws IOException { InputStreamReader reader = new InputStreamReader(System.in);BufferedReader input = new BufferedReader(reader); System.out.println("Dog");System.out.println("Cat");System.out.println("Cow");System.out.println("Horse");System.out.println("Sheep");System.out.print("Pick an Animal:");String animal = input.readLine();String animal2 = animal.toLowerCase();{ if(animal2.compareTo("dog")==0);System.out.println("Ruff, Ruff"); }}} http://vip.shadow-realm.org/fh/data/ksig.png
★ Maverick Posted October 1, 2004 Report Posted October 1, 2004 Dogman();<{POST_SNAPBACK}> Instead of this, put this in your code: try { Dogmain(); catch(IOException) { System.out.println("EEP! I/O Error encountered"); } http://java.sun.com/docs/books/tutorial/es...ial/exceptions/ -MMave Check out your zone population statistics at stats.sshq.net! MaverickSubspace Statistics AdministratorRetired SSCU Trench Wars Super ModeratorTWCore Coordinator Administrator
Himura Kenshin Posted October 1, 2004 Author Report Posted October 1, 2004 ok now heres another problem eww lol the error : Animals.java:10: 'catch' without 'try'catch(IOException) {^Animals.java:8: 'try' without 'catch' or 'finally'try {^2 errors and heres the code : import java.io.*; public class Animals{public static void main(String[] args){ try {Dogmain();catch(IOException) {System.out.println("EEP! I/O Error encountered");}}} public static void Dogman() throws IOException { InputStreamReader reader = new InputStreamReader(System.in);BufferedReader input = new BufferedReader(reader); System.out.println("Dog");System.out.println("Cat");System.out.println("Cow");System.out.println("Horse");System.out.println("Sheep");System.out.print("Pick an Animal:");String animal = input.readLine();String animall = animal.toLowerCase(); if((animall.compareTo("dog")==0)) {System.out.println("Ruff, Ruff"); }}} http://vip.shadow-realm.org/fh/data/ksig.png
Himura Kenshin Posted October 2, 2004 Author Report Posted October 2, 2004 mm? http://vip.shadow-realm.org/fh/data/ksig.png
MikeTheNose Posted October 3, 2004 Report Posted October 3, 2004 Closed. Technical support for Subspace/Continuum. - MikeTheNose- Subspace Central Network BanG Administrator-------------------------------------"I have never wavered in my commitments to this zone and I am certainly not doing so now." You just did.
Recommended Posts