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:
java.lang.ArrayIndexOutOfBoundsException: 98
I'm just wondering what causes this and how you could fix it. Thanks!
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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:
java.lang.ArrayIndexOutOfBoundsException: 98
I'm just wondering what causes this and how you could fix it. Thanks!
When I do this
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):java.lang.ArrayIndexOutOfBoundsException: 98
/home/newbi3/.encrypter/encrypted.log
But when I do this
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.
Last edited by copeg; July 10th, 2012 at 08:39 AM.