Okay i have the saving done for my tile map game done and it works perfect on the computer however on android it crashes everytime and i cant get hold of the stacktrace so please dont ask
here is my code
package com.hawk.engine.game.xml;
import java.io.IOException;
import java.io.Writer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.XmlReader;
import com.badlogic.gdx.utils.XmlReader.Element;
import com.badlogic.gdx.utils.XmlWriter;
import com.hawk.engine.game.input.Button;
import com.hawk.engine.game.level.BlockNames;
import com.hawk.engine.game.level.Level;
import com.hawk.engine.game.level.Tile;
import com.hawk.engine.game.level.ToolNames;
import com.hawk.engine.game.level.tiles.Water;
import com.hawk.engine.game.window.Window;
public class XMLMap {
// Button propertys
private static Button safeIconButton;
private static float timer,timercap;
private static FileHandle file;
private static Array<Element> list;
public static void create(){
safeIconButton = new Button(Window.mainSheet.getImage(ToolNames.getSAVEICON()), 30, Window.camera.viewportHeight-180, 60, 60, new Vector2(0,0));
timercap = 0.07f;
timer = 0;
}
public static void saveMap(String name){
file = Gdx.files.local(name+".xml");
Gdx.app.postRunnable(new Runnable(){
public void run(){
Writer writer = file.writer(false);
XmlWriter xml = new XmlWriter(writer);
try {
xml.element("map");
//int whatisit, int blockID, float x, float y, float width, float height, Vector2 velocity, boolean hasCollision, boolean object, int objectID
for(int i = 0;i < Level.lengthX;i++){
for(int j = 0;j < Level.lengthX;j++){
Tile t = Level.tiles[i][j];
xml.element("t").attribute("w", t.getBlockDef()).attribute("bID", t.getBlockVecID())
.attribute("x", t.getX()).attribute("y", t.getY()).attribute("wi", t.getWidth()).attribute("he", t.getHeight()).attribute("vx", 0).attribute("vy", 0)
.attribute("co", t.isCollision()).attribute("o", t.isObject()).attribute("oID", t.getObjectID()).pop().flush();
}
}
xml.pop();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
public static void render(float delta){
safeIconButton.render(delta);
}
public static void tick(float delta){
safeIconButton.tick(delta);
if(timer > timercap){
timer = 0;
if(safeIconButton.isClicked){
saveMap("map1");
}
}
timer += delta;
}
public static void loadMap(String name){
// Element e = XML.out.get(i * XML.lengthX + j);
// Map.tiles[i][j].setX(Integer.parseInt(e.getAttributeValue("x")));
// Map.tiles[i][j].setY(Integer.parseInt(e.getAttributeValue("y")));
//
// Map.tiles[i][j].setCropX(Integer.parseInt(e.getAttributeValue("imagecropX")));
// Map.tiles[i][j].setCropY(Integer.parseInt(e.getAttributeValue("imagecropY")));
XmlReader xml = new XmlReader();
try {
list = xml.parse(Gdx.files.local(name+".xml")).getChildrenByName("t");
} catch (IOException e1) {
e1.printStackTrace();
}
Gdx.app.postRunnable(new Runnable(){
public void run(){
for(int i = 0;i < Level.lengthX;i++){
for(int j = 0;j < Level.lengthX;j++){
// Loads all tiles
Element e = list.get(i * Level.lengthX + j);
Level.tiles[i][j] = new Tile(Integer.parseInt((e.getAttribute("w"))), Integer.parseInt((e.getAttribute("bID"))), Float.parseFloat((e.getAttribute("x"))), Float.parseFloat((e.getAttribute("y"))), Float.parseFloat((e.getAttribute("wi"))), Float.parseFloat((e.getAttribute("he"))), new Vector2(0,0), Boolean.parseBoolean((e.getAttribute("co"))), Boolean.parseBoolean((e.getAttribute("o"))), Integer.parseInt((e.getAttribute("oID"))));
// Adds water
// WATER AT EDGE
if(i >= 1 && j == 1 || i == 1 && j >= 1 || i >= 1 && j == Level.lengthX-2 || i == Level.lengthX-2 && j >= 1 || i >= 2 && j == 2 || i == 2 && j >= 2 || i >= 2 && j == Level.lengthX-3 || i == Level.lengthX-3 && j >= 2){
Level.tiles[i][j] = new Water(Tile.TILE,BlockNames.WATERID, i*Level.tileSizeWidth, j*Level.tileSizeHeight, Level.tileSizeWidth,Level.tileSizeHeight, new Vector2(0,0),false);
}
if(i >= 0 && j == 0 || i == 0 && j >= 0 || i >= 0 && j == Level.lengthX-1 || i == Level.lengthX-1 && j >= 0){
Level.tiles[i][j] = new Water(Tile.TILE,BlockNames.WATERID, i*Level.tileSizeWidth, j*Level.tileSizeHeight, Level.tileSizeWidth,Level.tileSizeHeight, new Vector2(0,0),true);
}
//-----------------------------------------
}
}
}
});
}
}