Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My original code:
- package objectclass;
- import java.io.*;
- public class Objectclass
- {
- public static void main(String[] args) throws Exception
- {
- BufferedReader inKb = new BufferedReader(new InputStreamReader (System.in));
- BufferedReader inFile = new BufferedReader(new FileReader("dogslist.txt"));
- String line = inFile.readLine();
- int count = 0;
- Dogs[] parlour = new Dogs[16];
- while(line != null)
- {
- String[] field = line.split("#");
- int age = Integer.parseInt(field[2]);
- parlour[count] = new Dogs(field[0],field[1],age);
- System.out.println(parlour[count]);
- count++;
- line = inFile.readLine();
- }
- String search = inKb.readLine();
- for(int i=0;i<count;i++)
- {
- if(search.equals(parlour[count].getName().toUpperCase()))
- {
- System.out.println(parlour[i]);
- }
- }
- }
- }
- My text File:
- Jerry#German Sheapord#4
- Owen#cat#3
- Morgan#MathsGenius#7
- My error:
- run:
- Name: Jerry
- Breed: German Sheapord
- Age: 4
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
- Name: Owen
- Breed: cat
- Age: 3
- at objectclass.Objectclass.main(Objectclass.java:17)
- C:\Users\Morgan\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
- BUILD FAILED (total time: 0 seconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement