null refrence when adding dictionary

i am adding a text file in dictionary but it is giving error
NullReferenceException: Object reference not set to an instance of an object

original File

aa
aah
aahed
aahing
aahs
aal
aalii
aaliis
aals

Code:

import System.Collections.Generic;
import System.Linq;

var MytextAsset:TextAsset;
var myDictionary :Dictionary.<String,String>;
function Start () {
   
    /* split the text file up by newline characters */
 
    var textLines : String [] = MytextAsset.text.Split("/rn"[0]);  
    myDictionary.Add(textLines[0], textLines[0]);

}

the error is in last line…

1 Answer

1

You just declared the type of myDictionary, you didn’t instantiate it.

Have a look at THIS.

You need to do :

var myDictionary = new Dictionary.<String,String>();

instead of

var myDictionary :Dictionary.<String,String>;