뷰어를 만들고 있습니다. 처음으로 디렉토리로 이동할 때, 파일을 처리하고, 이미지를 정확하게 만들고, 데이터 파일로 데이터를 직렬화하여 데이터 파일을 작성합니다. 그런 다음 새로 만든 파일을 볼 수있는 형식으로 deserialize합니다. 두 번째로 디렉토리로 이동하면 ans가 해당 파일을 deserialize하여 양식을 채 웁니다. 처음에는 시스템을 생성해야 할 때 시스템이 올바르게 작동하지만 이미 있으면 참조되지 않은 오브젝트 오류가 발생합니다. 내가 뭘 놓치고 있니?직렬화 - 비 직렬화 (이진)
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
listView1.Items.Clear();
fileInfoList.Clear();
//fileNameList.Clear();
ClearFlowPanel();
TreeNode newSelected = e.Node;
DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
dirPath = nodeDirInfo.FullName;
label_selectedPath.Text = dirPath;
foreach (FileInfo file in nodeDirInfo.GetFiles("*.sbs", option))
{
if (file.Extension == ".sbs")
{
fileInfoList.Add(file);
}
}
foreach (FileInfo info in fileInfoList)
{
ListViewItem i = listView1.Items.Add(info.Name, 1);
i.SubItems.Add(SizeInKB(info.Length));
i.SubItems.Add(info.LastWriteTime.ToShortDateString());
}
listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
string binData = dirPath + "\\" + ".browser" + "\\" + "_browser.bin";
if (File.Exists(binData))
{
DeserializeData(binData); //creates error
}
}
private void DeserializeData(string binPath)
{
FileStream fs = new FileStream(binPath, FileMode.Open);
BinaryFormatter bin = new BinaryFormatter();
int length = (int)bin.Deserialize(fs);
MessageBox.Show(length.ToString());
for (int i = 0; i < length; i++)
{
viewerData[i] = (ViewerData)bin.Deserialize(fs); //problem
}
for (int i = 0; i < viewerData.Length; i++)
{
PopulateFlowControl(viewerData[i]);
viewerNameList.Add(viewerData[i].name);
}
}
private void UpdateDirectory()
{
thumbPath = dirPath + "\\" + ".browser";
if (!Directory.Exists(thumbPath))
{
Directory.CreateDirectory(thumbPath);
}
fileInfoArray = fileInfoList.ToArray();
viewerData = new ViewerData[fileInfoArray.Length];
string binData = thumbPath + "\\" + "_browser.bin";
Stream stream = File.Open(binData, FileMode.Create);
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(stream, fileInfoArray.Length);
ProgressBar_Form progressBar = new ProgressBar_Form(fileInfoArray.Length);
progressBar.Show();
for (int i = 0; i < fileInfoArray.Length; i++)
{
viewerData[i] = new ViewerData(fileInfoArray[i]);
bin.Serialize(stream, viewerData[i]);
progressBar.progressBar1.PerformStep();
progressBar.label_progress.Text = "Processing : " + fileInfoArray[i].Name;
viewerData[i].image.Dispose();
if (File.Exists(viewerData[i].imagePath))
{
File.Delete(viewerData[i].imagePath);
}
}
stream.Close();
progressBar.Close();
DeserializeData(binData); //works fine
}
편집 :
오류 : 개체의 인스턴스로 설정되지 않았습니다 개체 참조 - 라인에 DeserializeData (문자열 binPath)에서 루프 먼저 '문제를'댓글을 달았습니다;
스택 추적 ... X에서 Substance_Browser_12.Form1.DeserializeData (문자열 binPath)에서
: 비주얼 스튜디오 2010 \ 프로젝트 \ \ 물질 디자이너 \ Substance_Browser_12 \ Substance_Browser_12 \ Form1.cs를 : Substance_Browser_12에서 라인 (151) . X : \ Visual Studio 2010 \ Projects \ Substance Designer \ Substance_Browser_12 \ Substance_Browser_12 \ Form1.cs의 Form1.treeView1_NodeMouseClick (개체 보낸 사람, TreeNodeMouseClickEventArgs e) : System.Windows.Forms.TreeView.OnNodeMouseClick (TreeNodeMouseClickEventArgs e)의 줄 at 줄 System.Windows.Forms.TreeView.WmNotify (메시지 &m) at System.Windows.Forms.TreeView.WndProc (메시지m) System.Windows.Forms.Control.ControlNativeWindow.OnMessage (메시지 & m) System.Windows.Forms.Control.ControlNativeWindow.WndProc에서 (메시지 & m) 에서 System.Windows.Forms.NativeWindow.DebuggableCallback에서 (HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) 에서 System.Windows.Forms.Control.SendMessage (Int32, Int32 msg, IntPtr 매개 변수, IntPtr 매개 변수) System.Windows.Forms.Control.WmNotify에서 System.Windows.Forms.Control.ReflectMessageInternal (HWND를 IntPtr, 메시지 & m) 에서 MSG,을 IntPtr의 WPARAM, LPARAM을 IntPtr의) (메시지 & m) System.Windows.Forms.Control.ControlNativeWindow.OnMessage (메시지 & m) 에서 System.Windows.Forms.ScrollableControl.WndProc (메시지 & m)에서 t System.Windows.Forms.Control.WndProc (메시지 & m) System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message &m)에서 (System.Windows.Forms.NnsWebModel) System.Windows.Forms.Control.DefWndProc에서 System.Windows.Forms.NativeWindow.DefWndProc (메시지 & m) 에서 .CallWindowProc (WNDPROC을 IntPtr, HWND를 IntPtr, INT32의 MSG,을 IntPtr의 wParam,을 IntPtr의 lParam) (메시지 0,123,224 System.Windows.Forms.Control에서 System.Windows.Forms.TreeView.WndProc (메시지 & m) 에서 9,미터) System.Windows.Forms.TreeView.WmMouseDown에서 & m은 MouseButtons 버튼, INT32 클릭 수 (메시지) .ControlNativeWindow.OnMessage (메시지 & m) System.Windows.Forms.NativeWindow.DebuggableCallback에서 System.Windows.Forms.Control.ControlNativeWindow.WndProc (메시지 & m) 에서 (HWND를 IntPtr, INT32의 MSG,을 IntPtr의 WPARAM, LPARAM을 IntPtr의) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg) at System.Windows.System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 이유, ApplicationContext 컨텍스트)의 에서 (시스템의 경우) 시스템에서 을 입력하십시오. Forms.Application.ComponentManager.System.Windows. .Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run (양식 mainForm) at Substance_Browser_12.Program.Main() in X : \ Visual Studio 2010 \ Projects System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args)의 (System.AppDomain._nExecuteAssembly에서 (런타임 어셈블리 어셈블리, 문자열 [] args) 에서 System.AppDomain.ExecuteAssembly ~에서 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 시스템에서 System.Threading.ExecutionContext.RunInternal에서 System.Threading.ThreadHelper.ThreadStart_Context (개체 상태) (의 ExecutionContext의 ExecutionContext, ContextCallback 콜백, 부울 preserveSyncCtx을 상태 개체) 에서 . Threading.ExecutionContext.Run (ExecutionContext에 ExecutionContext에, ContextCallback 콜백, 객체 상태 부울 preserveSyncCtx) System.Threading.ThreadHelper.ThreadStart에서 System.Threading.ExecutionContext.Run (ExecutionContext에 ExecutionContext에, ContextCallback 콜백, 객체 상태)에서 ()
참조되지 않은 개체 오류가 발생한 줄은 무엇입니까? – paqogomez
오류 메시지와 스택 추적을 제공 할 수 있습니까? – Grundy
실제 예외 텍스트를 추가해 주셔서 감사합니다. "개체 참조가 개체의 인스턴스로 설정되지 않았습니다"는 "참조되지 않은 개체 오류"와 같은 의미는 아닙니다. 오해의 소지가 있습니다. – groverboy