Results 1 to 6 of 6
  1. #1
    dorien is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default 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.

    ** This space for rent **

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: array index out of bounds : 0 problem

    java.lang.ArrayIndexOutOfBoundsException: 0
    The error is from trying to access an empty array. There is no element in the first position: 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.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,438
    Blog Entries
    7
    Rep Power
    20

    Default 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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: array index out of bounds : 0 problem

    Quote Originally Posted by dorien View Post
    I'm working on a schoolproject where I need to solve freecell automatically with a program. I found a program online
    Does your school assignment really require finding a program online?
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  6. #6
    dorien is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default 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.

    Quote Originally Posted by awinston View Post
    Does your school assignment really require finding a program online?
    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

  1. array index out of bounds
    By searcher in forum New To Java
    Replies: 3
    Last Post: 01-21-2012, 02:27 PM
  2. having an array index out of bounds problem
    By samanyu in forum New To Java
    Replies: 18
    Last Post: 06-03-2011, 08:12 AM
  3. Replies: 4
    Last Post: 01-31-2011, 08:20 PM
  4. Array Index Out Of Bounds and Problem in Assigning Values
    By chronoz1300 in forum New To Java
    Replies: 2
    Last Post: 12-28-2009, 07:14 PM
  5. Array Index out of bounds
    By leapinlizard in forum New To Java
    Replies: 5
    Last Post: 04-29-2009, 05:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •