
-----------------------------------
worthless
Tue Mar 31, 2015 3:51 pm

PLEASEEEEEEHELP MEEEEE ITS DUE TMR  String index out of range: -1
-----------------------------------

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Rovarspraket
 * 
 * @author 
 * @version
 * 
 */

public class Rovarspraket
{

	public static void main(String


AND I GOT THIS
[code]
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.charAt(Unknown Source)
	at Rovarspraket.main(Rovarspraket.java:27)
[/code]

Mod Edit: Please syntax="java" or code BBcode tags to wrap your code and stuff.

-----------------------------------
Zren
Tue Mar 31, 2015 5:00 pm

RE:PLEASEEEEEEHELP MEEEEE ITS DUE TMR  String index out of range: -1
-----------------------------------
String.indexOf() will return -1 if it can't find the string you supply it.
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#indexOf(java.lang.String)

Try debugging what character you're trying to find. Use System.out.println() to print the values of your variables.

Example:


System.out.format("pos=%s\n", pos);
char letter = line.charAt(pos);
System.out.format("letter=%s\n", letter);
int consonantPos = consonant. indexOf(letter); 
System.out.format("consonantPos=%s\n", consonantPos);
char vowel=closestVowel.charAt(consonantPos); 
System.out.format("vowel=%s\n", vowel);


I'm guessing you forgot about the newline character (\n) or the whitespace character.
http://www.asciitable.com/index/asciifull.gif
