I am working on this program and I'm almost done but when I try to write a string to a file I get this error:
Code :java.lang.ArrayIndexOutOfBoundsException: 98
I'm just wondering what causes this and how you could fix it. Thanks!
Printable View
I am working on this program and I'm almost done but when I try to write a string to a file I get this error:
Code :java.lang.ArrayIndexOutOfBoundsException: 98
I'm just wondering what causes this and how you could fix it. Thanks!
When I do this
Code :public void write(String key, String password, File data) throws IOException { // Writes the encrypted string to a file. System.out.println(data); out = new BufferedWriter(new FileWriter(data, true)); out.write(encrypted(key, password)); out.newLine(); out.close(); System.out.println("Your password was saved successfuly! " + encrypted(key, password)); } }
I get this error
and the value of "data" is this (which is correct):Code :java.lang.ArrayIndexOutOfBoundsException: 98
Code :/home/newbi3/.encrypter/encrypted.log
But when I do this
Code :public void write(String key, String password) throws IOException { // Writes the encrypted string to a file. File data = new File("/home/newbi3/.encrypter/encrypted.log"); System.out.println(data); out = new BufferedWriter(new FileWriter(data, true)); out.write(encrypted(key, password)); out.newLine(); out.close(); System.out.println("Your password was saved successfuly! " + encrypted(key, password)); } }
I get no errors and the value of "data" is still the same. Why is this?
The exception's name says it all - there is an array index that is out of bounds. This occurs when attempting to access the index of an array or similar data type that does not exist (is smaller than zero, or larger than the array (-1)). This is explained in the API docs: http://docs.oracle.com/javase/6/docs...Exception.html
Edit: And please read the forum rules - don't duplicate the same question. I have merged your two threads.