Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Why is this String.Split() giving a object reference not set error?

$
0
0
this is giving a Null reference exception: object reference not set to an instance of an object but i cant figure out why, the error is near the end where it declares variable line2 as an array of line.split #pragma strict import System.IO; var names = new Array (); var platforms = new Array (); var genres = new Array (); var styles = new Array (); var clients = new Array (); var gamePanel : GameObject; var gamePane : GameObject; var test : boolean; var line = ""; function loadGameList () { var sr : StreamReader = new System.IO.StreamReader(Application.dataPath + "/" + "games.list"); var found = false; for(var i = 0; i < 15 || found == false; i++) { line = sr.ReadLine(); if(line == "#") { found = true; } else { var line2 = line.Split(","[0]); //this line is giving the error <---------- addNewGame(line2[0],parseInt(line2[1]),parseInt(line2[2]),parseInt(line2[3]),parseInt(line2[4])); } } addGameList(); sr.Close(); } i dont see anything wrong about var line2 = line.Split(","[0]); so i really dont understand why its giving a null reference error

Viewing all articles
Browse latest Browse all 1875

Trending Articles