在类中调用SpotifyLocalAPI时获取null引用

时间:2016-12-13 09:55:44

标签: c# class

我错过了一些非常明显的东西,但我不习惯和班级一起工作。

我使用SpotifyLocalAPI从Spotify(duuh)获取数据。我已经添加了一个类来清理一些代码(并让我老师开心)。但现在我被抛出一个nullreferenceexeption,我不明白为什么,因为相同的代码在form.cs中起作用。

在我的班上,我有类似的东西:

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;
        }
    }
}

我在NullReferenceExeption行以及string test行上获得this.。我知道我遗漏了一些基本的东西,但我不知道在哪里看。我把这个函数称为:

TrackHelper _track = new TrackHelper();
//Different scope:
_track.retrieveTrackData();

有人能指出我在这里失踪的东西吗?我看到它的方式是我声明_spotify,将.GetStatus()输出放入status变量并尝试将该变量中的数据写入string test。但显然我错过了一些东西......

0 个答案:

没有答案
相关问题