package pro;
import java.io.IOException;
import pro.ltf.LTFReader;
public class Level {
public Camera cam;
public Level(){
cam = new Camera();
}
/**
* Charge le niveau
* @param - path - Chemin du niveau à charger
* @return Si le niveau à bien été charger
*/
public boolean load(String path){
try {
LTFReader reader = new LTFReader(path);
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
}
package pro.ltf;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import pro.blocks.BlockList;
import pro.blocks.Block;
public class LTFReader {
private File f;
private FileInputStream fis;
private ArrayList<Block> blocks = new ArrayList<Block>();
public LTFReader(String path) throws IOException{
f = new File(path);
fis = new FileInputStream(f);
int currentByte;
String currentStr = new String();
while ((currentByte = fis.read()) != -1){
currentStr += (char)currentByte;
if (currentStr.endsWith(System.getProperty("line.separator"))){
read(currentStr);
currentStr = new String();
}
}
}
public void read(String str){
if (str.startsWith("block:")){
Block block = BlockList.getBlock(get(str, "id"));
block.setPosition(get(str, "x"), get(str, "y"));
}
}
private int get(String str, String key){
int index = str.indexOf(key + "(");
int endIndex = str.indexOf(')', index);
index += new String(key + "(").length();
return Integer.parseInt(str.subSequence(index, endIndex).toString());
}
}
package pro.blocks;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Rectangle;
public class Block {
private Image image;
private int x = 0;
private int y = 0;
private Rectangle boundingBox;
public Block(){
}
public void setPosition(int x, int y){
this.x = x;
this.y = y;
}
}
Fri Feb 17 19:48:46 CET 2012 INFO:Slick Build #274
Fri Feb 17 19:48:46 CET 2012 INFO:LWJGL Version: 2.8.3
Fri Feb 17 19:48:46 CET 2012 INFO:OriginalDisplayMode: 1920 x 1080 x 32 @60Hz
Fri Feb 17 19:48:46 CET 2012 INFO:TargetDisplayMode: 512 x 512 x 0 @0Hz
Fri Feb 17 19:48:46 CET 2012 INFO:Starting display 512x512
Fri Feb 17 19:48:46 CET 2012 INFO:Use Java PNG Loader = true
Fri Feb 17 19:48:46 CET 2012 INFO:Controllers not available
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at pro.blocks.BlockList.getBlock(BlockList.java:13)
at pro.ltf.LTFReader.read(LTFReader.java:37)
at pro.ltf.LTFReader.<init>(LTFReader.java:29)
at pro.Level.load(Level.java:22)
at pro.game.GameState.loadNextLevel(GameState.java:30)
at pro.game.GameState.init(GameState.java:17)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
at pro.GameLoader.<init>(GameLoader.java:18)
at pro.GameLoader.main(GameLoader.java:25)
Donc je ne peut pas vous en dire plus, car je ne comprend absolument pas d'où viens l'erreur ni comment la regler.
Je sait juste qu'elle arrive à "getBlock(int id)" dans BlockList.java .
En tout cas, merci à ceux qui auront le courage de lire ce code.
C'est juste que tu ne peux pas accéder à l'élement qui se situe à l'index 0 d'une List qui a 0 élement.
Une erreur que je ne comprend pas
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.