A
A
Alkantel2014-05-31 19:07:38
C++ / C#
Alkantel, 2014-05-31 19:07:38

Visual C# 2010 Express "Object reference does not point to an instance of an object."

Please help me find the error. I've been digging for half a day now. Occurs when a Button is clicked.
I bring the code

namespace HS_Conf
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            AppBody qw = new AppBody();
            string hValuePath = qw.SelectedRule.hPath;
            MessageBox.Show(hValuePath);
        }
    }

    public class AppBody
    {
        public ObservableCollection<T> AppCollection { get; set; }

        public AppBody()
        {
            AppCollection = new ObservableCollection<SomeData>{
                new T{Name="BMW", Count=20},
                new T{Name="Mercedess", Count=30},
                new T{Name="Таврия", Count=200}
            };
        }
        
        pкшм SomeData selectedRule;
        
        public SomeData SelectedRule
        {
            get { return selectedRule; }
            set { selectedRule = value; }
        }

        public string rr
        {
            get { return selectedRule.Name; }
            set { selectedRule.Name= value; }
        }
    }

    public class T
    {
        public string Name { get; set; }
        public string Count{ get; set; }

    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlexP11223, 2014-05-31
@AlexP11223

Apparently SelectedRule is null.

E
Eugene, 2014-05-31
@r4tz52

You are not assigning a value to the SelectedRule field anywhere, so it is null.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question