user586399
user586399

Reputation:

Problem using Properties.Resources class?

I have an XO game. It needs three pictures: X, O and ?. Program worked very well when pictures were near the exe bath. When I added three pictures to the resources, I have a null exception:

private Bitmap xImage;
private Bitmap oImage;
private Bitmap initImage;

this code is in constructor:

// old code
this.xImage = new Bitmap(Application.StartupPath + "\\x.jpg");
// works well

// new code
this.xImage = new Bitmap(Properties.Resources.XImage);
// Null reference exception is thrown here

Upvotes: 1

Views: 1809

Answers (1)

TinaMarie
TinaMarie

Reputation: 131

Check that the images are really in your resource file. Double-click on the Resources.resx file in your project, select "Images" from the top left, and verify that the three images are there, and that one of them is named "XImage". If they're not there, try re-adding them. If they're there with the wrong names, you can right-click on them to rename them.

The code looks correct as written.

Upvotes: 2

Related Questions