0

I'm having issues debugging my project as i'm getting a "An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object."

It appears it relates to the following line

Private allfiles = lynxin.GetFiles("*.txt")

from the below declarations

Public Class Form1

Private numfiles As Integer
Private AllDetail() As FileDetail
Private allfiles = lynxin.GetFiles("*.txt")
Private AllDetails(allfiles.Count) As FileDetail

I'm needing these set so they can be accessed for all controls within Form1

I've read through the troubleshooting tips but cannot seem to fix the issue without moving the line back within the control its primarily used in

John Saunders
  • 157,405
  • 24
  • 229
  • 388
elmonko
  • 585
  • 2
  • 7
  • 27
  • 1
    You are not creating allfiles as an object of a certain type? Instead you are trying to "use" it before creating it as an object/type ? – Louis van Tonder Nov 22 '13 at 13:07
  • 1
    Private allfiles as TYPE = ... – Nadeem_MK Nov 22 '13 at 13:13
  • 1
    Add `Sub New` to your form class. And write `allfiles = lynxin.GetFiles("*.txt")` inside it. You should have little trouble diagnosing the bug now. – Hans Passant Nov 22 '13 at 13:18
  • Thanks, I've tried adding "as type" and it still throws it out.I've tried adding to Sub New and it still throws the same error. I think Louis's comment is correct however i still can't workout how to fix. Thanks – elmonko Nov 22 '13 at 14:16
  • 1
    what is `lynxin` and where is it declared (and more important where is it instanced)? – Ňɏssa Pøngjǣrdenlarp Nov 22 '13 at 14:40
  • Sorry its declared also under the class heading `Private lynxin As New IO.DirectoryInfo(zMailbox)` and is the folder location of the stored text files. Thanks – elmonko Nov 22 '13 at 14:49
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Nov 22 '13 at 20:24

0 Answers0