嗨,大家好,當我嘗試執行該項目時,出現此錯誤,當我試圖存儲對象。正如你所看到的,這是允許用戶將值存儲在不同類中的提取表單。有3個不同類的價值將存儲在..你看我仍然是一個新手在C#的東西。我有客戶類,它將存儲客戶的細節,皮卡類與皮卡的細節和交付相同。而其他課程只有在發生時纔會存儲。我不知道如果是這樣的問題..讓我知道,如果你想看到更多的代碼..謝謝錯誤System.NullReferenceException
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace coursework2
{
public partial class PickupForm : Form
{
private MainForm mainform;
private Pickup thePickup;
private Delivery theDelivery;
private Visit theVisit;
public Pickup pickup
{
get { return thePickup;}
set { thePickup = value;}
}
public Delivery delivery
{
get { return theDelivery; }
set { theDelivery = value; }
}
public Visit visit
{
get { return theVisit; }
set { theVisit = value; }
}
public PickupForm()
{
InitializeComponent();
}
/*public MainForm ParentForm
{
get { return mainform; }
set { mainform = value; }
}*/
private void PickupForm_Load(object sender, EventArgs e)
{
if (thePickup != null)
{
textCname.Text = thePickup.PickupName;
textAddress.Text = thePickup.PickupAddress;
textDate.Text = theVisit.DateTime.ToString();
textDname.Text = theDelivery.DeliveryName;
textDaddress.Text = theDelivery.DeliveryAddress;
}
}
private void btnReturn_Click(object sender, EventArgs e)
{
this.Close();
/*mainform.Show();*/
}
private void btnClear_Click(object sender, EventArgs e)
{
textCname.Clear();
textAddress.Clear();
textDate.Clear();
textDname.Clear();
textDaddress.Clear();
}
private void btnPickup_Click(object sender, EventArgs e)
{
thePickup.PickupName = textCname.Text; //error occurs from this line
thePickup.PickupName = textAddress.Text;
theVisit.DateTime = DateTime.Parse(textDate.Text);
theDelivery.DeliveryName = textDname.Text;
theDelivery.DeliveryAddress = textDaddress.Text;
this.Close();
}
private void textDate_TextChanged(object sender, EventArgs e)
{
}
private void textCname_TextChanged(object sender, EventArgs e)
{
}
}
}
屬性名應當按照約定大寫字母開頭。 –