1
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 WindowsFormsApplication1
{
public partial class Form5 : Form
{
     private Pickups thePickups;
    //The pickups object being created/edited


    public Pickups appointment
    {   //Property to allow access to thePickups
        get { return thePickups; }
        set { thePickups = value; }
    }


    public Form5()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        thePickups.custName = textBox1.Text;
        thePickups.custAddress= textBox2.Text;
        thePickups.arrival = textBox3.Text;
        thePickups.delAddress = textBox4.Text;
        thePickups.delName = textBox5.Text;


        this.Hide();
        //Hide the form
    }

    private void Form5_Load(object sender, EventArgs e)
    {



      if (thePickups != null)
        {
            textBox1.Text = thePickups.custName;
            textBox2.Text = thePickups.delAddress.ToString();
            textBox3.Text = thePickups.arrival.ToString();
        } 
    }
    }
}

「オブジェクト参照がオブジェクトのインスタンスに設定されていません。これはプロジェクト内の多くのファイルの 1 つですが、エラーが発生した最初のファイルです。」というエラーが表示されます。ここで間違いを犯した場所を見つけるのに苦労しています。どんな助けでも大歓迎です。

4

3 に答える 3

0

「予定」を作成したプロパティに値を設定していることを確認する必要があります。button_click イベントでもこれを行います。

private void button1_Click(object sender, EventArgs e)
{
    if(thePickups != null)
    {
        thePickups.custName = textBox1.Text;
        thePickups.custAddress= textBox2.Text;
        thePickups.arrival = textBox3.Text;
        thePickups.delAddress = textBox4.Text;
        thePickups.delName = textBox5.Text;


        this.Hide();
        //Hide the form
    }
}
于 2012-12-05T15:31:05.797 に答える
0

それは私が盲目になるのか、それとも線が見えないのか

thePickups = new Pickups();

どこでも?

余談ですが、form.Hide も怪しく見えます。そこに隠しておきたいと本当に思っていますか?しかし、それはあなたの例外を説明しません。

于 2012-12-05T15:00:47.467 に答える
0

で定義thePickupsします。

 private Pickups thePickups;
//The pickups object being created/edited


public Pickups appointment
{   //Property to allow access to thePickups
    get { return thePickups; }
    set { thePickups = value; }
}

ただし、オブジェクトのインスタンスには決して設定しないでください。そして、このオブジェクトのインスタンスがそうであるかどうかを確認しようとしますnull

if (thePickups != null)
{

} 
于 2012-12-05T15:01:31.083 に答える