nullreferenceexception error in my script

Hi guys im kinda new with unity. Im getting an null reference exception in my code. Here is my code:

public class LoginUI : InputAwareWindow
{

[Inject]
Private AccountManager _xAccountManager;
    void Start ()
    {
      Username.text = _xaccount_manager.GetLastUsername();
      Password.text = _xaccount_manager.GetLastPassword();	
	
	if ( string.IsNullOrEmpty(Error.text) && string.IsNullOrEmpty(Username.text) )
	{
		Error.text = HelpText;
	}
    }

     void OnLogin()
     {
           if ( !string.IsNullOrEmpty(Username.text) )		
		   {
			
			_xaccount_manager.Login(Username.text, Password.text); <- error here
 		
    		NGUITools.SetActive(MyWaitUI, true);
		}
		else
		{
			Error.text = HelpText;
		}
      }
   }

Public class AccountManager : Basebehavior
{
    public void Login(string username, string password)
	{
		_username = username;
		_password = password;
		
		Dictionary<string, string> data = new Dictionary<string, string>();
		data["username"] = username;
		data["password"] = password;
		
		_server_link.Request("login", OnLoginResult, data);
	}
     
 }

im getting the error in line 19 the error is :

NullReferenceException: Object reference not set to an instance of an object
LoginUI.Start () (at Assets/VSB/Scripts/LoginUI.cs:228)

Thank you. Your help is much appreciated

Please specify what line. Edit your question to include a copy of the error from the console window.

please see edited code. thank you sir

1 Answer

1

try making your Start() into Awake() instead if you are using it just to initialize.

That makes no sense. Awake is called before Start. So in general Awake gives you more trouble than Start. If something is null in Start it's most likely null in Awake as well.