Click here to Skip to main content
15,910,878 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a WPF Media Player. While I try to display the percentage of Volume in the Label. I have written the following codes in sliderVolume.ValueChanged event.

C#
private void sliderVolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            isMuted = false;
            mePlayerMain.IsMuted = false;
            mePlayerMain.Volume = sliderVolume.Value;
            double per = ((sliderVolume.Value / sliderVolume.Maximum) * 100);
            String value = per.ToString();
            //Console.WriteLine(per.ToString());

            if (!(String.IsNullOrEmpty(value)))
                lbVolumePercent.Content = value;
            else
                lbVolumePercent.Content = "";
        }


Every time I try to run the project it throws an exception in BOLD line saying that Object Reference is not set to instance of an object.

Can you help me out? Thanks.
Posted
Updated 1-Nov-11 5:35am
v3
Comments
Sergey Alexandrovich Kryukov 1-Nov-11 12:35pm    
Not all relevant code is shown, as Griff explained.
--SA

Since you don't show us where you set (or even declare) the lbVolumePercent variable, we can only assume that you aren't setting it anywhere - it is the only part of that line which would normally throw that exception.

Put a breakpoint on the line, and see when it is occurring - it may be that it occurs before you actually get round to setting the variable it is referring to.
 
Share this answer
 
Comments
Jyoti Choudhury 1-Nov-11 11:44am    
lbVolumePercent is not a variable. It's a user control Label.
OriginalGriff 1-Nov-11 11:48am    
That still makes it a variable. And if it isn't null, and it's your user control, then you need to single step into the control to identify why setting the property is causing the problem.
Sergey Alexandrovich Kryukov 1-Nov-11 12:34pm    
Sure, a 5.
--SA
Jyoti Choudhury 7-Nov-11 13:04pm    
thanks Griff and SA
The best thing to do is to debug and step through code. Where-ever you get an error, you can stop at that point, take a look at that code and then figure out where the null is.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Nov-11 12:34pm    
Exactly. Voted 5.
--SA
Abhinav S 1-Nov-11 12:35pm    
Thank you SA.
Jyoti Choudhury 7-Nov-11 13:03pm    
thanks...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900