java - Why do I get a message that my array is empty even after initializing it? -
this part of project i'm working on, when try insert elements array geneids
error:
java.lang.arrayindexoutofboundsexception: 0
i have initialized array couple of lines before, why can't insert elements it?
else if (line.startswith("!dataset_table_begin")) { line = bufferedreader.readline(); string[] array = line.split("\t"); dataset.sampleids = arrays.copyofrange(array, 2, array.length); dataset.geneids = new string[(dataset.genesnumber)]; dataset.genesymbols = new string[(dataset.genesnumber)]; dataset.datamatrix = new float[dataset.genesnumber][dataset.samplesnumber]; int count = 0; while ((line = bufferedreader.readline()) != "!dataset_table_end") { string[] arry = line.split("\t"); system.out.println(arry[0]); dataset.geneids[count] = arry[0]; dataset.genesymbols[count] = arry[1]; (int = 2; < dataset.samplesnumber; i++) { dataset.datamatrix[count][i] = float.parsefloat(arry[i]); } count++; } }
you have initialized array results of split
.
if character in line tab character, you'll empty array result.
before using element in array should check length.
alternatively, use line.split( "\t", 2 )
. return 2 elements in array though both empty.
Comments
Post a Comment