Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt

  • VB.NET

Es gibt 14 Antworten in diesem Thema. Der letzte Beitrag () ist von timonator.

    Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt

    Hallo,
    Ich wollte ein Programm programmieren wo ich mehrere Bilder gleichzeitig öffnen und nachher bearbeiten kann. Im Moment will ich automatisch herausfinden welche Bilder Hoch-, Querformat oder Quadratisch sind.

    Hier mein Code:

    Quellcode

    1. Private Sub ÖffnenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ÖffnenToolStripMenuItem.Click
    2. OpenFileDialog1.ShowDialog()
    3. selectedFilesName = OpenFileDialog1.FileNames selectedFilesQuantity = selectedFilesName.Length
    4. For i = 1 To selectedFilesQuantity Dim j As Integer = i - 1
    5. selectedFilesImg.Images.Add(Image.FromFile(selectedFilesName(j)))
    6. If selectedFilesImg.Images.Item(j).Width > selectedFilesImg.Images.Item(j).Height Then selectedFilesFormat(j) = 1 ElseIf selectedFilesImg.Images.Item(j).Width < selectedFilesImg.Images.Item(j).Height Then selectedFilesFormat(j) = 2 ElseIf selectedFilesImg.Images.Item(j).Width = selectedFilesImg.Images.Item(j).Height Then selectedFilesFormat(j) = 0 End If
    7. ListBox1.Items.Add(selectedFilesFormat(j) + vbTab + selectedFilesName(j))
    8. Next
    9. End Sub

    Dann kommt aber dieser Fehler: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

    Schonmal Danke im Vorraus :)
    Die Fehlerdetails:

    Quellcode

    1. System.NullReferenceException wurde nicht behandelt.
    2. HResult=-2147467261
    3. Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    4. Source=Rand Entferner
    5. StackTrace:
    6. bei Rand_Entferner.Form1.ÖffnenToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\Carlo\documents\visual studio 2010\Projects\Rand Entferner\Rand Entferner\Form1.vb:Zeile 26.
    7. bei System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
    8. bei System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
    9. bei System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
    10. bei System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
    11. bei System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
    12. bei System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
    13. bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
    14. bei System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
    15. bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    16. bei System.Windows.Forms.Control.WndProc(Message& m)
    17. bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    18. bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
    19. bei System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
    20. bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    21. bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    22. bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    23. bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    24. bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    25. bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    26. bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    27. bei System.Windows.Forms.Application.Run(ApplicationContext context)
    28. bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    29. bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    30. bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    31. bei Rand_Entferner.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
    32. bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    33. bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    34. bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    35. bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    36. bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    37. bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    38. bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    39. bei System.Threading.ThreadHelper.ThreadStart()
    40. InnerException:
    System.NullReferenceException wurde nicht behandelt.
    HResult=-2147467261
    Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    Source=Rand Entferner
    StackTrace:
    bei Rand_Entferner.Form1.ÖffnenToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\Carlo\documents\visual studio 2010\Projects\Rand Entferner\Rand Entferner\Form1.vb:Zeile 26.
    bei System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
    bei System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
    bei System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
    bei System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
    bei System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
    bei System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
    bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
    bei System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
    bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    bei System.Windows.Forms.Control.WndProc(Message& m)
    bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
    bei System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
    bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    bei System.Windows.Forms.Application.Run(ApplicationContext context)
    bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    bei Rand_Entferner.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
    bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    bei System.Threading.ThreadHelper.ThreadStart()
    InnerException:
    SelectedFileFormat soll wahrscheinlich ein Array, Liste,... sein. Wie auch immer. Du musst das Teil irgendwo instanzieren. Das heißt mit dem New-Schlüsselwort eine Instanz davon erzeugen. In diesem Fall ist selectedFileFormat Nothing und deshalb kommt die Exception. Das wäre aber eher etwas für das Grundlagen Forum.


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.
    Wenn es du ein Array vom Typ Integer haben möchtst, ja. Nur musst du dann auch die Größe des Arrays angeben: msdn.microsoft.com/de-de/library/wak0wfyt(v=vs.110).aspx
    Achtung auch wenn es dort steht. Verwende bitte kein ReDim Schlüsselwort.


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.