C#C
C#3y ago
dismal

How do I fix 'Object reference not set to an instance of an object.'?

I have an app that you can change the background in. The background of a panel in Form1 is set with this function:
public void SetPanelBackgroundImage(Image backgroundImage)
{
      Form1.back_panel.BackgroundImage = backgroundImage;
}

back_panel is set to Public so it can be accessed from my other form (UC_tab_theme.cs) and Form1 is instanced from
Form1 Form1;

The parameter that I pass into my SetPanelBackgroundImage() function is Properties.Resources.blob_scene_haikei which is a valid path to the image.
I get error:
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=ProtoSploit
  StackTrace:
   at ProtoSploit.res.UCs.UC_tab_theme.SetPanelBackgroundImage(Image backgroundImage)

I'm new and I don't particularly understand c# yet, so I hope one of you can help.
Was this page helpful?