가 발생합니다은 (listApplications는 ListView 컨트롤입니다)이 코드 NullReferenceException이
private void ShowApplicationPropertiesForm() {
String FullPath = String.Empty;
String Title = String.Empty;
String Description = String.Empty;
Boolean Legacy = false;
Boolean Production = false;
Boolean Beta = false;
MyCustomListViewItemDescendant lvi = (MyCustomListViewItemDescendant)listApplications.SelectedItems[0];
FullPath = lvi.ExePath;
Title = lvi.Text;
Description = lvi.ToolTipText;
ApplicationProperties ap = new ApplicationProperties(
FullPath,
Title,
Description,
Legacy,
Production,
Beta);
ap.Show();
}
//overloaded form constructor
public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
this.Text = String.Format("{0} Properties", ATitle);
textBoxFullPath.Text = AFullPath;
textBoxTitle.Text = ATitle;
textBoxDescription.Text = ADescription;
checkBoxLegacy.Checked = ALegacy;
checkBoxProduction.Checked = AProduction;
checkBoxBeta.Checked = ABeta;
}
... 내가지고있어, "System.NullReferenceException는 처리되지 않은했다 메시지 = 개체 참조가 개체의 인스턴스로 설정되지 않았습니다. "
그것을 통해 스테핑 폭탄은 라인 :
textBoxFullPath.Text = AFullPath;
textBoxFullPath 폼에 텍스트 상자이다; "Q : \ 무엇 \ 이세요 곧 \ 마 \ BabyBlue.exe \"업데이트
: 부분적으로 해결
AFullPath는 종류의 유효한 값이 있습니다.
이전의 "조기 할당"문제였습니다. 할당자를 Load() 이벤트로 이동하면 더 이상 폭탄을 투하하지 않습니다 (아래 코드).
그러나 이제는 런타임시 폼에 아무 것도 표시되지 않습니다 ... ???!?
public partial class ApplicationProperties : Form {
String _fullPath = String.Empty;
String _title = String.Empty;
String _description = String.Empty;
Boolean legacy = false;
Boolean production = false;
Boolean beta = false;
public ApplicationProperties() {
InitializeComponent();
}
public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
_fullPath = AFullPath;
_title = ATitle;
_description = ADescription;
legacy = ALegacy;
production = AProduction;
beta = ABeta;
this.CenterToScreen();
}
private void ApplicationProperties_Load(object sender, EventArgs e) {
//this.Text = String.Format("{0} Properties", _title);
Text = String.Format("{0} Properties", _title);
textBoxFullPath.Text = _fullPath;
textBoxTitle.Text = _title;
textBoxDescription.Text = _description;
checkBoxLegacy.Checked = legacy;
checkBoxProduction.Checked = production;
checkBoxBeta.Checked = beta;
}
다시 업데이트 :
가 추가 "를 InitializeComponent를();" 오버로드 된 생성자에게 트릭을했습니다 - 감사합니다, SW!
어디에서'textBoxFullPath'를 초기화합니까? –
양식이 Visual Studio로 만들어 졌습니까? 그렇다면 InitializeComponent()에 대한 호출을 추가하여 TextBox 및 기타 UI 요소를 만들어야합니다. –
@JJ : String.Empty를 의미합니까? 습관. 아마도 도움이되지는 않지만 어떻게 상처받을 수 있는지 보지 못합니다. –