Results 1 to 6 of 6
- 08-14-2012, 11:35 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
array index out of bounds : 0 problem
Hi,
I'm working on a schoolproject where I need to solve freecell automatically with a program. I found a program online, but now I get this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
This is the part of the code that gives the error:
public static void main(String[] args) throws IOException {
Comparator<short[]> comp = FreeCellNode.comparator();
Scanner sc = new Scanner(new File(args[0]));
while (sc.hasNext()) {
int dealNumber = sc.nextInt();
System.out.println("Searching board:" + dealNumber);
FreeCellNode fcn = Deal.initialize(new File ("32000.txt"), dealNumber);
System.out.println(fcn.toString());
AnalyzeState st = new AnalyzeState();
DFS<short[]> dfs = new DFS<short[]>(st);
Result res = dfs.fullSearch(fcn, Deal.goal(), comp);
Stack<IMove> sol = res.solution();
System.out.println("Solution has " + sol.size() + " moves.");
System.out.println(" Total number of states: " + dfs.getCounter());
st.report();
I've tried to solve it myself, but I don't understand how an array can be out of bounds when you're calling index 0?
Can anyone please help me?
Cheers,
Dorien
- 08-14-2012, 01:09 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: array index out of bounds : 0 problem
Please use [code] tags [/code] when posting code.
Also, please post the full exception text, including stack trace, highlighting the line in your code from which it is thrown.Please do not ask for code as refusal often offends.
- 08-14-2012, 02:47 PM #3
Re: array index out of bounds : 0 problem
The error is from trying to access an empty array. There is no element in the first position: 0java.lang.ArrayIndexOutOfBoundsException: 0
You should test the array's length before trying to access its elements.If you don't understand my response, don't ignore it, ask a question.
- 08-14-2012, 03:02 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: array index out of bounds : 0 problem
That program needs a command line argument; what that argument means is up to you ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 08-14-2012, 04:34 PM #5
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
- 08-15-2012, 02:52 PM #6
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
Re: array index out of bounds : 0 problem
Hi,
thank you for your quick replies!
I think I figured it out now, with your help: The array is empty because I didn't give a command line argument.
This is just part of my project. I have to test if the symptoms of dementia can be detected by using digital games. I want to use the solver for freecell to compare with the users solution.
Thanks!
Dorien
Similar Threads
-
array index out of bounds
By searcher in forum New To JavaReplies: 3Last Post: 01-21-2012, 02:27 PM -
having an array index out of bounds problem
By samanyu in forum New To JavaReplies: 18Last Post: 06-03-2011, 08:12 AM -
problem with array error index out of bounds exception
By cn23271 in forum New To JavaReplies: 4Last Post: 01-31-2011, 08:20 PM -
Array Index Out Of Bounds and Problem in Assigning Values
By chronoz1300 in forum New To JavaReplies: 2Last Post: 12-28-2009, 07:14 PM -
Array Index out of bounds
By leapinlizard in forum New To JavaReplies: 5Last Post: 04-29-2009, 05:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks