I want to read the midi file but there is something wrong

I am trying to read the midi file into a sequence, but when I run it, there is an error showed up.
Here are the code I wrote and the error showed up:

I just add some code in the audio application template as image shown and gets the error,
I just wanna test my midi file readin functionality currently. Please Help!

As the error says, you need to check you correctly opened “something” (you got the data to work with) before doing anything with the data. Check the OpenButtonClicked() function in the Looping tutorial to see what I mean. There they do it with an audio file, but I guess the process will be similar with MIDI files.

Edit: if you are just reading a file and trying to play it I’m not sure why would you open a file everytime getNextAudioBlock is called: just operate with buffers here, handle all that file management stuff outside with another function

Oh thanks! does it mean i just create a new function outside to do the file read work?

Yes check the tutorial I linked in my other answer (or better, the advanced tutorial that reads the file without stopping the audio using a background thread). In both tutorials they just manage the file opening (and check before operating with data) in another function.