문제점이 있음 "개체 참조가 개체의 인스턴스로 설정되지 않았습니다"라는 오류가 발생하는 이유이 줄이 포함 된 프레젠테이션 계층의 오류 :"개체 참조가 개체의 인스턴스로 설정되지 않았습니다"오류
TempAccountManager.Accounts.Add (tempAccount);
Visual Studio 디버거를 사용하여 코드를 살펴보고 계정을 만들었습니다. 나는 액세스 변조자가 문제가 있다고 믿는다.
프리젠 테이션 레이어
using myBudget.BusinessObject;
using myBudget.BusinessLogic;
namespace myBudget
{
public partial class NewBudgetWizard : Form
{
public int CurrentStep { get; set; }
public Account TempAccount = new Account();
public AccountManager TempAccountManager = new AccountManager();
public NewBudgetWizard()
{
private void createAccountList(ListView lvAccounts)
{
foreach (ListViewItem lvi in lvAccounts.Items)
{
int tempAccNumber = Int32.Parse(lvi.SubItems[0].Text);
string tempAccName = lvi.SubItems[1].Text;
string tempAccType = lvi.SubItems[2].Text;
decimal tempAccBalance = decimal.Parse(lvi.SubItems[3].Text, System.Globalization.NumberStyles.Currency);
Account tempAccount = new Account(tempAccNumber, tempAccName, tempAccType, tempAccBalance, DateTime.Now);
TempAccount = new Account(tempAccNumber, tempAccName, tempAccType, tempAccBalance, DateTime.Now);
TempAccountManager.Accounts.Add(tempAccount);
}
}
}
}
비즈니스 로직 계층
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using myBudget.BusinessObject;
namespace myBudget.BusinessLogic
{
public class AccountManager : Account
{
public List<Account> Accounts { get; set; }
}
}
비즈니스 오브젝트
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myBudget.BusinessObject
{
public class Account
{
public int AccountID { get; set; }
public int UserID { get; set; }
public int Number { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public decimal Balance { get; set; }
public DateTime ReconcileTimeStamp { get; set; }
public Account()
{
}
public Account(int number, string name, string type, decimal balance, DateTime reconcileTimeStamp)
{
Number = number;
Name = name;
Type = type;
Balance = balance;
ReconcileTimeStamp = reconcileTimeStamp;
}
}
}
감사합니다! 나는 하나 이상의 답변에 투표 할 수 있기를 소원합니다. 전에 답변을 게시하고 더 많은 코드가 있으니 답변을 제출하십시오. –