NullReferenceException: Object reference not set to an instance of an object
Hi all. Can you help me, i got this error.
This error says, that string selected bold(number of string is 15) is incorrect.
var votes : int[];
completed=0;
var cont : int=0;
var mvote : String;
var votess : String[];
var nowi : int=0;
mvote=PlayerPrefs.GetString("Votes");
Debug.Log(mvote);
if (mvote=="") {
cont=1;
}else if (mvote!="") {
votess=mvote.Split(";"[0]);
Debug.Log(votess[0]);
while (votess[nowi]!="") {
**votes[nowi]=int.Parse(votess[nowi]);**
nowi=nowi+1;
Debug.Log("Succesfully");
}
}
Your votes array is not initialized. After initializing votess array using splitted mvote, you have to do:
votes = new int[votess.Length];
And another issue - in while loop, you’re testing votess[nowi] value, but if nowi will be outside of array length (and it will be after processing last element), you will get another exception. You have to change while condition to:
while (nowi < votess.Length)
bubzy
2
the string doesn’t exist, you have declared it but not initialized.
you will need something like
for (i = 0; i < arraySize ;i++)
{
votes *= 0;*
}
i think you can also
votes = null;
in the void Start(){} function