Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6680295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:27:29+00:00 2026-05-26T04:27:29+00:00

Honestly… I haven’t got a clue what I’m doing wrong… I get the error

  • 0

Honestly… I haven’t got a clue what I’m doing wrong… I get the error

Object reference not set to an instance of an object

The code is shown below and I have the marked the error using the /////.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MonuEventPlanning
{
    public partial class Form1 : Form
    {
        DinnerFun dinnerFun; 

    public Form1()
    {
        InitializeComponent();
        DinnerFun dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value }; 
    }

    public void btnCalc_Click(object sender, EventArgs e)
    {
        dinnerFun.CalcDrinks(cbxHealthy.Checked); ///////PROBLEM HERE////////////////
        dinnerFun.CalcDecorations(cbxFancy.Checked);
        DisplayCost(); 
    }

    public void DisplayCost()
    {
        tbxDisplayCost.Text = dinnerFun.CalcTotalCost(cbxHealthy.Checked).ToString("c"); 
    }
}

}

Here is my other page of code with this practice project I am doing:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MonuEventPlanning
{
    public partial class Form1 : Form
    {
        DinnerFun dinnerFun; 

    public Form1()
    {
        InitializeComponent();
        DinnerFun dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value }; //This object is instantiated again?  Or is this the same dinnerFun from above?  
    }

    public void btnCalc_Click(object sender, EventArgs e)
    {
        dinnerFun.CalcDrinks(cbxHealthy.Checked);
        dinnerFun.CalcDecorations(cbxFancy.Checked);
        DisplayCost(); 
    }

    public void DisplayCost()
    {
            tbxDisplayCost.Text = dinnerFun.CalcTotalCost(cbxHealthy.Checked).ToString("c"); 
        }
    }
}

Some help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:27:30+00:00Added an answer on May 26, 2026 at 4:27 am

    In the constructor you are not putting the DinnerFun object in the dinnerFun member that you have declared in the form. You are creating another local variable with the same name inside the constructor. When you try to use the member later on, it will still be null.

    Just remove the variable declaration from the assignment:

    public Form1() {
      InitializeComponent();
      dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value }; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Somewhere some guy said (I honestly do not know where I got this from),
Honestly I'm very bad at CSS and not good at dealing with color /
Preface : I'm honestly not sure if this should be on StackOverflow, SuperUser or
I'm working on a security project in Javascript (something I honestly have not used),
I'm not used to writing JS, honestly, and to make matters worse I'm working
So I have a question I'm honestly not quite sure how to ask. Essentially
The Jquery script that controls my tabcontainer gives an object expected runtime error. I
Honestly, I'm not even sure the best way to go about this, but essentially,
I can't find a duplicate for this question, but I honestly hope I'm not
Hello and hopefully thanks for the help. Honestly I am not very experienced at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.