+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18

Thread: Creating new instance of an object

  1. #11
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    What if you did this:
    Code:
    myObject newObj = null;
    
    instead of:
    Code:
    myObj newObj;
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  2. #12
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    is it because it expects you to do something in if or else section???

  3. #13
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    What if you did this:
    Code:
    myObject newObj = null;
    
    instead of:
    Code:
    myObj newObj;
    
    Yeah, I tried that and it seemed to stop the problem. Just wondered why it gives that error if I don't put = null...I thought it should be null by default.

  4. #14
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    It is null by default. And like I said, it's not an actual error. It's just a warning. It's basically saying that you haven't assigned it anything. This COULD be a problem if you didn't have the proper checks in place, i.e., if you didn't check if it was null it would result in an object reference error.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #15
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by micky View Post
    is it because it expects you to do something in if or else section???
    There is something inside them in my code m. I was just using this to show the idea....

    Don't think that would be a problem though.

  6. #16
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Quote Originally Posted by richyrich View Post
    There is something inside them in my code m. I was just using this to show the idea....

    Don't think that would be a problem though.
    i know i should'nt have said something

  7. #17
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    It is null by default. And like I said, it's not an actual error. It's just a warning. It's basically saying that you haven't assigned it anything. This COULD be a problem if you didn't have the proper checks in place, i.e., if you didn't check if it was null it would result in an object reference error.
    Yeah, that's pretty much what I thought. I wonder why it highlights the if condition rather than the original variable though...Never mind... Should be good to go now...

    I just don't like anything in that box in VS...

  8. #18
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Quote Originally Posted by richyrich View Post
    I just don't like anything in that box in VS...
    me neither, R.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. Calling void isn't creating instance of an object
    By richyrich in forum .NET Development
    Replies: 5
    Last Post: March 14th, 2010, 11:43 AM
  2. Creating a scheduler
    By noFriends in forum .NET Development
    Replies: 8
    Last Post: June 29th, 2009, 08:35 AM
  3. Creating a drop down box from the css
    By dtz in forum HTML & CSS Help
    Replies: 1
    Last Post: March 12th, 2009, 09:10 AM
  4. Object reference not set to an instance of an object
    By Shem in forum .NET Development
    Replies: 4
    Last Post: July 22nd, 2008, 05:59 AM
  5. Object reference not set to an instance of an object
    By jmurrayhead in forum .NET Development
    Replies: 1
    Last Post: May 29th, 2008, 11:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO