arrays - InvalidCastException: Cannot cast from source type to destination type -



arrays - InvalidCastException: Cannot cast from source type to destination type -

i have fetched info xml , stored in array.i have coded below

private var dataarray=new array(); private var timearray=new array(); private var distancearray=new array(); private var detailstock : string; private var distancedata : string; private var timedata : string; private var datalist : string; private var info : string; function readme() { var filepath : string = application.datapath+"/xmldocs/"+"stock"+".xml"; var xmldoc : xmldocument = new xmldocument(); if(file.exists (filepath)) { xmldoc.load( filepath ); var stock_list : xmlnodelist = xmldoc.getelementsbytagname("stock"); for(var : int = 0; < stock_list.count;i++) { // getting kid nodes of stock, rice , wheat in list var stockitems_list : xmlnodelist = stock_list.item(i).childnodes; // running loop through items nowadays in stock for(var j : int = 0; j < stockitems_list.count; j++) { //debug.log("stockitems_list count"+stockitems_list.count); // taking properties of item list cost , quantity var stockitemsproperties_list : xmlnodelist = stockitems_list.item(j).childnodes; for(var k : int = 0; k < stockitemsproperties_list.count; k++) { //debug.log("length....."+ stockitemsproperties_list[k].innertext); data=stockitemsproperties_list[k].innertext+"\t"; //debug.log(data); /*--------pushed total info array-----------*/ // dataarray=new array(); dataarray.push(data); //debug.log("elements in array"+dataarray); } //var stockitemsproperties_list : xmlnodelist =stockitems_list[j]. // getting names of items rice , wheat detailstock+="\n"+stockitems_list[j].name+"\n"; // know cost stored @ oth element of stockitemsproperties_list detailstock+=stockitemsproperties_list[0].name+" "; // inner text of stockitemsproperties_list[0] (price node) contains money detailstock+=stockitemsproperties_list[0].innertext+" "+"rs"+"\n"; // , quantity @ 1st element of stockitemsproperties_list detailstock+=stockitemsproperties_list[1].name+" "; // inner text of stockitemsproperties_list[1] (quantity node) contains quantity in kg detailstock+=stockitemsproperties_list[1].innertext+" "+"kg"+"\n"; //debug.log("distance"+stockitemsproperties_list[0].innertext); //debug.log("seconds"+stockitemsproperties_list[1].innertext); distancedata=stockitemsproperties_list[0].innertext; distancearray=new array(); distancearray.push(distancedata); //debug.log("distance array............ "+distancearray); /*--------------print time time array -----------------*/ timedata=stockitemsproperties_list[1].innertext; timearray=new array(); timearray.push(timedata); // debug.log("time array............ "+timearray); /*-------------distance , time both array array ------------------*/ for(var d=0;d<distancearray.length;d++) { for(var t=0;t<timearray.length;t++) { // debug.log("distance : " +distancearray[d] +" "+"time: "+timearray[t]+"\n"); transform.position-=new vector3(0,distancearray[d],0); debug.log(transform.position); } }

with above code iam able print values.

but want move object based on values stored in distancearray. transform.position-=new vector3(0,distancearray[d],0);

the code moving object getting below exception

invalidcastexception: cannot cast source type destination type. boo.lang.runtime.runtimeservices.checknumericpromotion (iconvertible convertible) boo.lang.runtime.runtimeservices.checknumericpromotion (system.object value) boo.lang.runtime.runtimeservices.unboxsingle (system.object value) xmldatareader.readxml () (at assets/script/xmldatareader.js:286) xmldatareader.ongui () (at assets/script/xmldatareader.js:141)

what issue.any problem variable declaration type?.please help me out

this unityscript.

the issue caused distancedata beingness string, hence distancearray beingness array of string, not int.

try this:

class="snippet-code-html lang-html prettyprint-override">private var distancedata : int; ... distancedata = parseint(stockitemsproperties_list[0].innertext);

though malformed xml can reason.

arrays string exception unity3d boo

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -