I'm missing something really obvious, but I'm not used to working with classes.
I use the SpotifyLocalAPI to fetch data from Spotify (duuh). I've added a class to clean up some code (and to make my teacher happy). But now I get thrown a nullreferenceexeption, and I don't see why, since the same code does work in the form.cs.
In my class I have something like this:
namespace Lyricify
{
class TrackHelper
{
private static SpotifyLocalAPI _spotify;
public void retrieveTrackData()
{
_spotify = new SpotifyLocalAPI();
StatusResponse status = _spotify.GetStatus();
string test = status.Track.TrackResource.Name;
Console.WriteLine(test);
this.track = status.Track.TrackResource.Name;
this.artist = status.Track.ArtistResource.Name;
this.album = status.Track.AlbumResource.Name;
}
}
}
I get a NullReferenceExeption on the string test line, and on the this. lines. I know I'm missing something basic, but I have no idea where to look. I call this function like this:
TrackHelper _track = new TrackHelper();
//Different scope:
_track.retrieveTrackData();
Can somebody point me to what I'm missing here? The way I see it is that I declare the _spotify, put the .GetStatus() output into the status variable and try to write data from that variable into the string test. But appearently I'm missing something...