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#
  4. exception

exception

Scheduled Pinned Locked Moved C#
help
7 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.
  • N Offline
    N Offline
    NasimKaziS
    wrote on last edited by
    #1

    Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. What could be the reason for the error.

    where there is a will there is a way

    Z 1 Reply Last reply
    0
    • N NasimKaziS

      Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. What could be the reason for the error.

      where there is a will there is a way

      Z Offline
      Z Offline
      ZeeshanAhmedpk
      wrote on last edited by
      #2

      This error may occurs when the object is not inilized. Use this: myClass myObject = new myClass(); OR myClass myObject = null; myObject = new myClass();

      N N 2 Replies Last reply
      0
      • Z ZeeshanAhmedpk

        This error may occurs when the object is not inilized. Use this: myClass myObject = new myClass(); OR myClass myObject = null; myObject = new myClass();

        N Offline
        N Offline
        NrmMyth
        wrote on last edited by
        #3

        ZeeshanAhmedpk wrote:

        myClass myObject = null; myObject = new myClass();

        Why this?

        S 1 Reply Last reply
        0
        • N NrmMyth

          ZeeshanAhmedpk wrote:

          myClass myObject = null; myObject = new myClass();

          Why this?

          S Offline
          S Offline
          Sk8tzz
          wrote on last edited by
          #4

          Its null reference because you havent instantiated or assigned to an instance. Why it throws an exception is because you using even though it is null reference. Hope this answers your question..

          .NET Rules

          N 1 Reply Last reply
          0
          • S Sk8tzz

            Its null reference because you havent instantiated or assigned to an instance. Why it throws an exception is because you using even though it is null reference. Hope this answers your question..

            .NET Rules

            N Offline
            N Offline
            NrmMyth
            wrote on last edited by
            #5

            myObject = new myClass(); But you have assigned myObject to an instance...

            S 1 Reply Last reply
            0
            • N NrmMyth

              myObject = new myClass(); But you have assigned myObject to an instance...

              S Offline
              S Offline
              Sk8tzz
              wrote on last edited by
              #6

              Hi.. The exception only get thrown were you use the null reference, can you post the code, and give the line num that tthrows the exception. Maybe we can see what you really trying to do. :doh::~

              .NET Rules

              1 Reply Last reply
              0
              • Z ZeeshanAhmedpk

                This error may occurs when the object is not inilized. Use this: myClass myObject = new myClass(); OR myClass myObject = null; myObject = new myClass();

                N Offline
                N Offline
                NasimKaziS
                wrote on last edited by
                #7

                hi. my error got rectified, that was because i had used transactions and missed out to assign the transaction property for the command object. regards -----------------------------------------------------------------

                where there is a will there is a way

                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