Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. My original code:
  2.  
  3. package objectclass;
  4. import java.io.*;
  5.  
  6. public class Objectclass
  7. {
  8. public static void main(String[] args) throws Exception
  9. {
  10. BufferedReader inKb = new BufferedReader(new InputStreamReader (System.in));
  11. BufferedReader inFile = new BufferedReader(new FileReader("dogslist.txt"));
  12. String line = inFile.readLine();
  13. int count = 0;
  14. Dogs[] parlour = new Dogs[16];
  15.  
  16. while(line != null)
  17. {
  18. String[] field = line.split("#");
  19. int age = Integer.parseInt(field[2]);
  20. parlour[count] = new Dogs(field[0],field[1],age);
  21. System.out.println(parlour[count]);
  22. count++;
  23. line = inFile.readLine();
  24. }
  25.  
  26.  
  27.  
  28. String search = inKb.readLine();
  29. for(int i=0;i<count;i++)
  30. {
  31. if(search.equals(parlour[count].getName().toUpperCase()))
  32. {
  33. System.out.println(parlour[i]);
  34. }
  35. }
  36.  
  37.  
  38. }
  39.  
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46. My text File:
  47.  
  48. Jerry#German Sheapord#4
  49. Owen#cat#3
  50. Morgan#MathsGenius#7
  51.  
  52.  
  53. My error:
  54.  
  55. run:
  56. Name: Jerry
  57. Breed: German Sheapord
  58. Age: 4
  59. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
  60. Name: Owen
  61. Breed: cat
  62. Age: 3
  63. at objectclass.Objectclass.main(Objectclass.java:17)
  64. C:\Users\Morgan\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
  65. BUILD FAILED (total time: 0 seconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement