0

I'm a pre-service teacher and supposed to be teaching students VB. I was doing a course on Linkedin Learning and following their instructions and I get this error. I'm not new to programming and have years of experience in other languages, but this is my first foray into .Net and VB. I really don't know why I'm getting the error, as there is no possible reason for it. As soon as I execute the program I get the error. If you look at the screen shot you see textBlock1 has no value. Screenshot of error

Yet it has a default value and should not be "nothing".

Screenshot of window and default value

I have really no idea why it's doing this or how to fix it. It is the most simplest program. Basically, this bit of code is supposed to put in textBlock1 whatever is being entered in textBox1. I'd greatly appreciate any help you could provide.

dbasnett
  • 11,334
  • 2
  • 25
  • 33
  • 3
    Firstly, please don't post pictures of code or error messages. They are both text and should be posted as text, formatted appropriately. We can't copy and paste text from screenshots to run code or search for error messages. – jmcilhinney Jun 02 '21 at 13:17
  • As for the issue, you don't need to guess. The debugger will tell you whether a reference is `Nothing` or not so use it. If it's not something on the line where execution broke, look at the exception information and see where the exception was actually thrown. There's lots of information available there that you have ignored. – jmcilhinney Jun 02 '21 at 13:18
  • 2
    [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) - Specifically, there is even a section on WPF (which I added) that addresses common issues. One of the most likely is that you have event handlers that reference other controls which are firing during form creation before `InitializeComponent` is complete. If those handlers reference not-yet-created controls you get a null-reference exception. To resolve it, ensure that your handlers don't access other controls until loading is complete. – J... Jun 02 '21 at 13:21
  • Thank you that post helped. I did not see it when I was searching. I appreciate the help. – Coach SamF Jun 02 '21 at 13:37

0 Answers0