public class Tube { private int x; private int y; private Texture t01; private Tube[] tubes; //<---------------- private Random r; public Tube(){ r= new Random(); x = 400 ; y = 0; t01 = new Texture("tube.png"); tubes = new Tube[3]; //<------------------------------ for (int i = 0; i<tubes.length;i++){ tubes[i] = new Tube(); tubes[i].x = r.nextInt(10); tubes[i].y = r.nextInt(10); } } public void drawTube(SpriteBatch batch){ for (int i = 0; i<tubes.length;i++) { batch.draw(t01, tubes[i].x, tubes[i].y); } } Do I understand correctly that you cannot create an array of the Tube [] object in the same Tube class. If so, why? How else to implement it?
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.StackOverflowError at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:133) Caused by: java.lang.StackOverflowError at java.io.InputStream.<init>(InputStream.java:45) at java.io.FileInputStream.<init>(FileInputStream.java:123) at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:140) at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222) at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:146) at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98) at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100) at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92) at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:88)