Results 1 to 3 of 3
- 10-05-2012, 08:04 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
Error : Exception in thread "main" how can it be fixed?
import java.util.HashMap;
public class zadatak {
public static void main(String[] args) {
String input = args[0];
String [] numbers = input.split("_");
HashMap<String, Integer> frequency = new HashMap<String, Integer>();
for(int i = 0; i < numbers.length; i++){
if(frequency.containsKey(numbers[i])){
Integer value = frequency.get(numbers[i]);
value++;
frequency.put(numbers[i], value);
}
else{
frequency.put(numbers[i], 1);
}
}
for(String key : frequency.keySet()){
System.out.print(key + "_" + frequency.get(key) + " ");
}
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at zadatak.main(zadatak.java:6)
After running this program I keep getting this error msg,can u please advice me, how can it be fixed?
Thanks!
- 10-05-2012, 08:34 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Error : Exception in thread "main" how can it be fixed?
Did you write that program yourself? If so, you must've forgotten that it needs (at least) one command line argument to run.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-05-2012, 10:37 PM #3
Arma virumque cano
- Join Date
- Oct 2012
- Location
- Indianapolis
- Posts
- 20
- Rep Power
- 0
Re: Error : Exception in thread "main" how can it be fixed?
Yeah,
Example
In this example, "-x" and "dosomething" get stored in the args[] array. So you would have arg[0] and arg[1]Java Code:COMMAND LINE C:\Folder> myProgram.exe -x dosomthing
If you were to just run myProgram.exe with no arguments, the args[] array would be empty. It wouldn't have anything at arg[0]
Similar Threads
-
"Exception in thread "main" java.lang.NoSuchMethodError: main"
By isnkumar in forum New To JavaReplies: 2Last Post: 06-20-2012, 12:18 AM -
Error:Exception in thread "main" java.lang.NoSuchMethodError:main
By jerry jessie in forum New To JavaReplies: 6Last Post: 01-21-2012, 05:59 AM -
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks