1

I use the following code:

WMPEqualizerSettingsCtrl eq = null;
eq.enhancedAudio = true;

But I get an error:

Object reference not set to an instance of an object.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Tallal Kazmi
  • 361
  • 2
  • 13

1 Answers1

1

Yes, you've set the eq object equal to null when declaring it. That is what produces the exception: you can't set the properties of an object that doesn't exist!

If you want to create an instance of the WMPEqualizerSettingsCtrl class, just use new:

WMPEqualizerSettingsCtrl eq = new WMPEqualizerSettingsCtrl();
eq.enhancedAudio = true;   // now eq exists, so it won't throw an exception!

I don't know exactly what the WMPEqualizerSettingsCtrl class is, but you might need to pass some parameters to the constructor. Those provide the class with additional information about exactly how you want it to be created.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 2
    Yes but WMPEqualizerSettingsCtrl is an interface, does not supports new clause ! – Tallal Kazmi Jan 15 '12 at 10:18
  • 1
    @tkaz: Then you can't set properties on it. You can't instantiate interfaces. You have to find a class that *implements* that interface. Check the documentation to see how to create an object of that type. – Cody Gray - on strike Jan 15 '12 at 10:19