Results 1 to 3 of 3
  1. #1
    stubz151 is offline Member
    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Default Help with stack overflow error.

    This is the error main" java.lang.StackOverflowError" i've googled it and it appears to be about storing to much info. I think the error is coming from my array usage (i just learnt how to do them) , here the code for the whole class .

    package squash;
    import javax.swing.*;
    import java.io.*;
    import java.util.*;



    /**
    *
    *
    * @author stubz
    */
    public class Myscanner {

    varaibles v = new varaibles();
    int size=0;
    String [] readarray=new String [100];
    public Myscanner()
    {

    }
    void read() throws FileNotFoundException
    {
    Scanner scFile = new Scanner(new File("scores.txt"));
    while(scFile.hasNext())
    {
    readarray[1]=scFile.nextLine();
    size++;
    scFile.close();
    }
    }

    public String output()
    {
    String temp="";
    for (int i=0;i<1;i++)
    {
    temp=temp+readarray[i]+"\n";

    }
    return temp;
    }

    void Write() throws IOException
    {

    PrintWriter outfile;
    outfile = new PrintWriter(new FileWriter("scores.txt"));
    String []writearray=new String [6];
    writearray[1]=v.getplayer1();
    writearray[2]=v.getplayer2();
    writearray[3]=""+v.getgames1();
    writearray[4]=""+v.getgames2();
    for(int i=0;i<1;i++)
    {
    outfile.println(writearray[i]);
    outfile.close();
    }
    }


    }

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Help with stack overflow error.

    When you post code, please use code tags. Also, check out the link in my sig regarding naming conventions.

    A stack overflow is usually caused by recursion. I don't see any recursion in your code, but I'm not looking very hard since it's hard to follow with the lack of formatting.
    Get in the habit of using standard Java naming conventions!

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,388
    Rep Power
    5

    Default Re: Help with stack overflow error.

    Normally, a stack overflow is caused by recursively invoking a method from inside the same method without providing an avenue of exiting or returning. It is analogous to an infinite loop. Nothing I can see in your code shows that happening. Your class, varaibles (sp?) may be causing the problem (e.g. your invoking a new instance inside the constructor.

    Also, class names should begin with an upper case letter and your code should be placed between code tags [code][/code].

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. GSON causing stack overflow error?
    By cele1989 in forum New To Java
    Replies: 2
    Last Post: 10-29-2012, 11:35 AM
  2. Stack Overflow?
    By kyle_maddisson in forum New To Java
    Replies: 5
    Last Post: 11-17-2011, 11:49 AM
  3. Gui problem and stack overflow error
    By zaricpp in forum Advanced Java
    Replies: 5
    Last Post: 06-03-2011, 09:54 AM
  4. Replies: 1
    Last Post: 03-17-2010, 05:25 AM
  5. Graphics2D: stack overflow error
    By rosh72851 in forum New To Java
    Replies: 11
    Last Post: 10-15-2008, 09:01 PM

Posting Permissions

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