jdizzle1988
Newbie
Ok so I have this problem where I store info to an internal file using fileOutputStream() and then I start another intent and pull that information using the fileInputStream() method. I then parse the inputStr for indexes of ";" (those are my delimeters). I then do a inputStr.substring(0, index) and store that in a section of an array (infoArray). I loop until all ";" (fields) have been extracted and stored in the array. I then put each item from the array into a variable. This is where the program errors out because I can comment just this section out and the program works flawelessly. Can anyone help? code below.
public
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
setContentView(R.layout.game);
String FILENAME = "monster";
String inputStr = "";String[] infoArray =
new String[4];
String info;
String inputStr1 = "";
int index;
String inputStr1 = "";
int index;
byte[] byteArray = newbyte[102400];
int bytesRead = 0;
int bytesRead = 0;
try {
FileInputStream fstream = new FileInputStream(FILENAME);
while((bytesRead = fstream.read(byteArray)) != -1) {
inputStr = new String(byteArray,0,bytesRead);
while((bytesRead = fstream.read(byteArray)) != -1) {
inputStr = new String(byteArray,0,bytesRead);
}
inputStr1 = inputStr;
inputStr1 = inputStr;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0; i == 4; i++) {
index = inputStr1.indexOf(";");
info = inputStr1.substring(0, index);
inputStr1 = inputStr1.substring(index, inputStr1.lastIndexOf(";"));
infoArray = info;
}
info = inputStr1.substring(0, index);
inputStr1 = inputStr1.substring(index, inputStr1.lastIndexOf(";"));
infoArray = info;
}
TextView tvMonsterID1 = (TextView) this.findViewById(R.id.tvMonsterID1);
TextView tvMonsterHealth1 = (TextView) this.findViewById(R.id.tvMonsterHealth1);
TextView tvMonsterName1 = (TextView)this.findViewById(R.id.tvMonsterName1);
TextView tvMonsterAtk1 = (TextView)this.findViewById(R.id.tvMonsterAtk1);
TextView tvMonsterDef1 = (TextView)this.findViewById(R.id.tvMonsterDef1);
ImageView imgMonsterPic1 = (ImageView) this.findViewById(R.id.imgMonsterPic1);
TextView tvMonsterHealth1 = (TextView) this.findViewById(R.id.tvMonsterHealth1);
TextView tvMonsterName1 = (TextView)this.findViewById(R.id.tvMonsterName1);
TextView tvMonsterAtk1 = (TextView)this.findViewById(R.id.tvMonsterAtk1);
TextView tvMonsterDef1 = (TextView)this.findViewById(R.id.tvMonsterDef1);
ImageView imgMonsterPic1 = (ImageView) this.findViewById(R.id.imgMonsterPic1);
if (infoArray[1] == "Shewanadon") {
imgMonsterPic1.setImageResource(R.drawable.two);
} else {
imgMonsterPic1.setImageResource(R.drawable.icon);
}
imgMonsterPic1.setImageResource(R.drawable.two);
} else {
imgMonsterPic1.setImageResource(R.drawable.icon);
}
/**--------This is where the code craps out------------------
String ID = infoArray[0];
String Health = infoArray[1];
String Name = infoArray[2];
String atk = infoArray[3];
String def = infoArray[4];
---------------------------------------------------------*/
String Health = infoArray[1];
String Name = infoArray[2];
String atk = infoArray[3];
String def = infoArray[4];
---------------------------------------------------------*/
tvMonsterID1.setText("ID: " + ID);
tvMonsterHealth1.setText("Health : " + Health);
tvMonsterName1.setText("Name: " + Name);
tvMonsterAtk1.setText("Attack: " + atk);
tvMonsterDef1.setText("Defense: " + def);tvMonsterHealth1.setText("Health : " + Health);
tvMonsterName1.setText("Name: " + Name);
tvMonsterAtk1.setText("Attack: " + atk);