Java - String value is not getting saved in String array -


in below code;

steporexpected[i][k] = "step"; system.out.println(steporexpected[i][k]); 

by using loop , k, saving values in steporexpected (two dimensional array). problem here string not getting saved. if print right after assigned value steporexpected, printing null.

moreover, if print , k, both values correct.

please suggest why string not getting saved in 2 dimensional array.

i have pasted code below, problem facing in

(if (steplstnode.getnodename().equals("step")) { steporexpected[i][k] = "step";) 

actual code:

if (modulenamelstnode.getnodetype() == node.element_node)  {     nodelist tclst = modulenamelstnode.getchildnodes();      tccount = docinput.getelementsbytagname("tc").getlength();     system.out.println(tccount);     tcid = new string[tccount];     //tcdepend = new string[tccount];     tcdescription = new string[tccount];     stepcountinatcofmodule = new int[tccount];     expectedresult = new string[tccount];     actualresult_pass = new string[tccount];     actualresult_fail = new string[tccount];     //result.xmlcreator();     int i=0;     steporexpected = new string [tccount][100];     action = new string [tccount][100];     refobj = new string [tccount][100];     val = new string [tccount][100];      (int tc = 0; tc < tclst.getlength(); tc++)      {          int k=0;         node tclstnode = tclst.item(tc);          if (tclstnode.getnodetype() == node.element_node)          {             system.out.println(tclstnode.getnodename());              tcid[i] = objecttype.getattribute(tclstnode,"id");             //tcdepend[i] = objecttype.getattribute(tclstnode,"depend");             tcdescription[i] = objecttype.getattribute(tclstnode,"description");              nodelist steplst = tclstnode.getchildnodes();               system.out.println(steplst.getlength());             (int step = 0; step < steplst.getlength(); step++)              {                 node steplstnode = steplst.item(step);                  if (steplstnode.getnodetype() == node.element_node)                  {                      if (steplstnode.getnodename().equals("step"))                     {                         steporexpected[i][k] = "step";                         action[i][k] = objecttype.getattribute(steplstnode,"action");                         refobj[i][k] = objecttype.getattribute(steplstnode,"refobj");                         val[i][k] = objecttype.getattribute(steplstnode,"val");                         stepcountintc++;                         k++;                         system.out.println(i);                         system.out.println(k);                         system.out.println(objecttype.getattribute(steplstnode,"action"));                         system.out.println(steporexpected[i][k]);                     }                     else if (steplstnode.getnodename().equals("expected"))                     {                         steporexpected[i][k] = "expected";                         action[i][k] = objecttype.getattribute(steplstnode,"expaction");                         refobj[i][k] = objecttype.getattribute(steplstnode,"exptarget");                         val[i][k] = objecttype.getattribute(steplstnode,"expval");                         stepcountintc++;                         k++;                     }                     else if (steplstnode.getnodename().equals("expectedresult"))                     {                         expectedresult [i] = steplstnode.gettextcontent();                     }                     else if (steplstnode.getnodename().equals("actualresult_pass"))                     {                         actualresult_pass [i] = steplstnode.gettextcontent();                     }                     else                     {                         actualresult_fail [i] = steplstnode.gettextcontent();                     }                  }//step nodetype              }//step               stepcountinatcofmodule[i] = stepcountintc;             i++;             stepcountintc = 0;          }//tc if      }//tc } 

the culprit k++;. incrementing k before printing console. so, modify code following,

steporexpected[i][k] = "step"; action[i][k] = objecttype.getattribute(steplstnode,"action"); refobj[i][k] = objecttype.getattribute(steplstnode,"refobj"); val[i][k] = objecttype.getattribute(steplstnode,"val");    system.out.println(i); system.out.println(k); system.out.println(objecttype.getattribute(steplstnode,"action")); system.out.println(steporexpected[i][k]); stepcountintc++; //moved counter k++; //moved counter 

everything should work, expected.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -