Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. some strange error

some strange error

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiohelpquestion
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mark Salsbery

    :-D You must be new if you're a stranger to the NullReferenceException! For .NET-related question there's at least two other message boards here that will be more helpful: (Managed) C++/CLI[^] .NET Framework[^]

    T Offline
    T Offline
    thesad
    wrote on last edited by
    #3

    I looked (Managed) C++/CLI and .NET Framework, I used search and found nothing about NullReferenceException! Do you know something about it??

    M 1 Reply Last reply
    0
    • T thesad

      I looked (Managed) C++/CLI and .NET Framework, I used search and found nothing about NullReferenceException! Do you know something about it??

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #4

      I meant ask your question on one of those message boards - C++/CLI is probably the most appropriate since this isn't a framework question :) The NullReferenceException class' name says it all - it's the exception thrown when you try to dereference a null reference. NullReferenceException Class[^] It should be clear in the debugger which line of your code is using a reference that hasn't been initialized/allocated yet. You may have to view the call stack to find the line in your code (when the exception occurs).

      T 1 Reply Last reply
      0
      • M Mark Salsbery

        I meant ask your question on one of those message boards - C++/CLI is probably the most appropriate since this isn't a framework question :) The NullReferenceException class' name says it all - it's the exception thrown when you try to dereference a null reference. NullReferenceException Class[^] It should be clear in the debugger which line of your code is using a reference that hasn't been initialized/allocated yet. You may have to view the call stack to find the line in your code (when the exception occurs).

        T Offline
        T Offline
        thesad
        wrote on last edited by
        #5

        debugger shows, taht tihs error comes at this code : this->b_em.pct->Load("b_em.jpg"); this->b_em.pct->Location = System::Drawing::Point(13, 64); this->b_em.pct->Size = System::Drawing::Size(5, 5); this->b_em.pct->TabIndex = 3; this->b_em.pct->TabStop = false; this->b_em.pct->Visible = false; so where is probelm ?:)

        M 1 Reply Last reply
        0
        • T thesad

          debugger shows, taht tihs error comes at this code : this->b_em.pct->Load("b_em.jpg"); this->b_em.pct->Location = System::Drawing::Point(13, 64); this->b_em.pct->Size = System::Drawing::Size(5, 5); this->b_em.pct->TabIndex = 3; this->b_em.pct->TabStop = false; this->b_em.pct->Visible = false; so where is probelm ?:)

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #6

          Unfortunately I have never used forms with .NET. There's many helpful people on the .NET boards that have though :) I have no idea what class your "this->b_em.pct" object is so, based on what I see, the only guess I can make is the Load() method call is failing - is the b_em.jpg file in the app exe folder or in the system path? Mark

          T 1 Reply Last reply
          0
          • M Mark Salsbery

            Unfortunately I have never used forms with .NET. There's many helpful people on the .NET boards that have though :) I have no idea what class your "this->b_em.pct" object is so, based on what I see, the only guess I can make is the Load() method call is failing - is the b_em.jpg file in the app exe folder or in the system path? Mark

            T Offline
            T Offline
            thesad
            wrote on last edited by
            #7

            b_em is from structure ref struct tank { int step_x, step_y; System::Windows::Forms::PictureBox^ pct; }; b_em.jpg is at app exe folder that code is at void InitializeComponent(void) function

            H M 2 Replies Last reply
            0
            • T thesad

              b_em is from structure ref struct tank { int step_x, step_y; System::Windows::Forms::PictureBox^ pct; }; b_em.jpg is at app exe folder that code is at void InitializeComponent(void) function

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #8

              Dear thesad if you ask on the correct forum(Managed C++/CLI) you can find your answer early


              WhiteSky


              1 Reply Last reply
              0
              • T thesad

                b_em is from structure ref struct tank { int step_x, step_y; System::Windows::Forms::PictureBox^ pct; }; b_em.jpg is at app exe folder that code is at void InitializeComponent(void) function

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #9

                Ok. I'll take another wild guess - pct is NULL. Maybe try //System::Windows::Forms::PictureBox^ pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct->Load(... You can save yourself lots of typing by omitting the implied "this->" :)

                T 1 Reply Last reply
                0
                • M Mark Salsbery

                  Ok. I'll take another wild guess - pct is NULL. Maybe try //System::Windows::Forms::PictureBox^ pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct = gcnew System::Windows::Forms::PictureBox(); b_em.pct->Load(... You can save yourself lots of typing by omitting the implied "this->" :)

                  T Offline
                  T Offline
                  thesad
                  wrote on last edited by
                  #10

                  many thanks Mark, it really help :):):)

                  M 1 Reply Last reply
                  0
                  • T thesad

                    I'm learning c++ and using visual studio c++ 2005 express edition. I had written a lot of program's code and try to run, and when it should be started I got an error : An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll Additional information: Object reference not set to an instance of an object. What must I do, that this error disapear ???

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #11

                    Your first step should be to set a breakpoint with the debugger ( F9 ) and examine your code to see which line blows up, then check to see what variable is null, causing the error. Everything else, is flailing in the dark.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                    1 Reply Last reply
                    0
                    • T thesad

                      many thanks Mark, it really help :):):)

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #12

                      You are welcome :) Really, consider the C++/CLI board for future CLI-related questions. I get so confused trying to think in .NET when I'm on the C++ board. Cheers! Mark "flailing in the dark" Salsbery ;)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups