Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:55:21+00:00 2026-05-30T07:55:21+00:00

I am getting an exception when running the following code. Public Function getSongs() As

  • 0

I am getting an exception when running the following code.

Public Function getSongs() As Song()
   ' Dim dir As New DirectoryInfo(Application.ExecutablePath)
     Dim dir As New DirectoryInfo(directory)
     Dim songsInDir() As Song = Nothing
     Dim i As Integer = 0
     For Each file As FileInfo In dir.GetFiles()
        'only read ".mp3" files
        If file.Extension = ".mp3" Then
            songsInDir(i) = New Song(file.Name)
            i = +i
        End If
    Next
    Return songsInDir
End Function

I get an error on line:

songsInDir(i) = New Song(file.Name)

I get an uncaught exception that says:

“Object reference not set to an instance of an object.”

The song object has a:

Public Sub new(By Val filename as String)

… sub that sets a variable and retrieves file info (this code works)

Any help would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:55:23+00:00Added an answer on May 30, 2026 at 7:55 am

    Try using a list:

    Public Function getSongs() As Song()
      Dim dir As New DirectoryInfo(directory)
      Dim songsInDir() As New List(of Song)
      For Each file As FileInfo In dir.GetFiles()
        'only read ".mp3" files
        If file.Extension = ".mp3" Then
          songsInDir.Add(New Song(file.Name)
        End If
      Next
      Return songsInDir.ToArray()
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i am getting the following exception while running my application and my applicationContext.xml
I am getting he following Exception while running my Quartz Schdular program. Below is
I am getting following exception while running BIRT from a Linux OS. Caused by:
I am running the following code /** * @param args */ public static void
I have the following code but I am getting an exception that a smtp
I am getting errors running the following code. I have provided comments to describe
I am running the following code in eclipse but getting a class not found
While running the following code i am getting the error java.lang.OutOfMemoryException : java heap
I am getting a Method not found: 'Boolean MyCompany.LibraryAssembly.SomeFunction(System.String)' exception/error when running a VB.NET
I am getting Following Exception while configuring the Connection Pool in Tomcat This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.