stack overflow - java.lang.StackOverflowError while adding items to list -


trying add items list , print them, compiles, i'm getting run time error theres stack on flow error. error prints out:

exception in thread "main" java.lang.stackoverflowerror @ list.<init>(list.java:5) @ list.<init>(list.java:9) @ list.<init>(list.java:9) <----- line repeated quite few times  

this code methods adding , print list.

public class list {  private athletenode front;  public list(){ front = null; }  public list athletes = new list();  //add athlete end of list  public void add(athlete a){  athletenode node = new athletenode (a); athletenode current; //temp node iterate on list  if(front == null)     front = node;//adds first element  else{     current = front;     while (current.next !=null)     current = current.next;     current.next=node;     }  } 

in class list, have list instance field gets initialized @ declaration

public list athletes = new list(); 

this means every list have list has list has list, ad nauseam, causing stackoverflowerror being constructed.

i'm not sure meant field, since aren't using anywhere. remove it.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -