NullReferenceException in built version but works fine in editor?

Hello, I’ve got a UI Image with a Button component assigned to it. There, I’ve got an OnClick() event, which is attached to a script. When playing normally in the editor the event is working fine but when I build the game and play it, I get a NullReferenceException. How can I solve this problem?
Thanks.

Well, look at the details in the log; they will tell you exactly which script and line the error occurs on. Then inspect that line and ask yourself how it could be null.

If stumped, post that method here, and tell us which line it occurs on, and see if somebody else has a bright idea.

(If it helps, I once ran into just such a problem because I didn’t realize that Debug.Assert is completely stripped out in built apps — along with any code you might be calling in its parameter list. So, that’s something to watch out for.)

I found out, that the error happens at an Invoke call:

Invoke("PlaceResBuilding", 7f);
...
void PlaceResBuilding()
        {
            int res_number = Random.Range(0, 3);
            string res_name = "House" + res_number.ToString();
            GameObject res = (GameObject)Instantiate(GameObject.Find(res_name), gameObject.transform.position, Quaternion.Euler(gameObject.transform.eulerAngles.x, gameObject.transform.eulerAngles.y + 90f, gameObject.transform.eulerAngles.z));
            DemandManager.res_demand -= 10f;
}

How can I solve this? Thanks!

OK, solved it by myself. Turned out to be a problem with sprite assignment.