An unhandled exception of type 'System.NullReferenceException' occurred

Discussion in 'C++' started by erictham115@gmail.com, Oct 27, 2005.

  1. Guest

    Hi i am a novice in C++ programming and encountered the following
    problem without headway - a popout appeared after successful
    compilation and linking with:
    "An unhandled exception of type 'System.NullReferenceException'
    occurred in rational.exe
    Additional information: Object reference not set to an instance of an
    object."

    On pressing break, the code stopped at the fract[0] which is a private
    class Rational member:

    int* rational::setrational(int n, int d)
    {
    div_t div_result;
    const int size = 3;
    if (n > d )
    {
    div_result = div(n,d);
    fract[0]= div_result.quot; --> code execution stopped here
    fract[1]= div_result.rem;
    fract[2]= d;
    }
    else
    {
    fract[0]= 0; <---- or here.
    fract[1]= n;
    fract[2]= d;

    };

    return fract;

    Can anyone help? thanks
     
    , Oct 27, 2005
    #1
    1. Advertising

  2. Ian Guest

    Re: An unhandled exception of type 'System.NullReferenceException'occurred

    wrote:
    > Hi i am a novice in C++ programming and encountered the following
    > problem without headway - a popout appeared after successful
    > compilation and linking with:
    > "An unhandled exception of type 'System.NullReferenceException'
    > occurred in rational.exe
    > Additional information: Object reference not set to an instance of an
    > object."
    >
    > On pressing break, the code stopped at the fract[0] which is a private
    > class Rational member:
    >

    Does the array fract exist? Has it been initialised, or simply declared?

    Ian
     
    Ian, Oct 27, 2005
    #2
    1. Advertising

  3. Re: An unhandled exception of type 'System.NullReferenceException'occurred

    wrote:
    > Hi i am a novice in C++ programming and encountered the following
    > problem without headway - a popout appeared after successful
    > compilation and linking with:
    > "An unhandled exception of type 'System.NullReferenceException'
    > occurred in rational.exe
    > Additional information: Object reference not set to an instance of an
    > object."
    >
    > On pressing break, the code stopped at the fract[0] which is a private
    > class Rational member:
    >
    > int* rational::setrational(int n, int d)
    > {
    > div_t div_result;
    > const int size = 3;
    > if (n > d )
    > {
    > div_result = div(n,d);
    > fract[0]= div_result.quot; --> code execution stopped here
    > fract[1]= div_result.rem;
    > fract[2]= d;
    > }
    > else
    > {
    > fract[0]= 0; <---- or here.
    > fract[1]= n;
    > fract[2]= d;
    >
    > };
    >
    > return fract;
    >
    > Can anyone help? thanks
    >


    Presumably fract is a null pointer. How it got to be a null pointer and
    what it should be instead is impossible to tell from the code posted.

    john
     
    John Harrison, Oct 27, 2005
    #3
  4. Acken Guest

    Thanks John & Ian. Will follow your suggestion to check on the code...
     
    Acken, Oct 28, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pardhasaradhy
    Replies:
    1
    Views:
    545
    Natty Gur
    Jul 9, 2003
  2. Lee Simpson
    Replies:
    0
    Views:
    1,615
    Lee Simpson
    Jul 18, 2003
  3. NicK chlam via DotNetMonster.com
    Replies:
    0
    Views:
    4,914
    NicK chlam via DotNetMonster.com
    Mar 21, 2005
  4. Ankit Aneja
    Replies:
    5
    Views:
    11,740
    Steven Cheng[MSFT]
    Apr 6, 2006
  5. Warren Tang
    Replies:
    1
    Views:
    907
    Warren Tang
    Sep 23, 2008
Loading...

Share This Page