안녕 얘들 아 내가 프로젝트를 실행하려고하면 개체를 저장하려고 할 때이 오류가 나타납니다. 보시다시피, 이것은 사용자가 다른 클래스에 값을 저장할 수있는 픽업 양식입니다. 거기에 가치가 저장됩니다 3 가지 클래스가 있습니다 .. 당신은 여전히 C# 일에 신비입니다 참조하십시오. 나는 고객의 세부 사항, 픽업의 세부 사항을 가진 픽업 클래스 및 납품과 같은 것을 저장할 고객 클래스를 가지고있다. 다른 클래스 방문은 시간이 발생할 때만 저장됩니다. 그게 문제가 있다면 내가 당신에게 당신은 thePickup
의 속성을 액세스하는오류 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)
{
}
}
}
속성 이름은 관례 대문자로 시작해야 각각의 속성을 초기화해야합니다. –