android - ListView.setAdapter error: java.lang.NullPointerException : <p>I am getting error "java.lang.NullPointerException" by setting my adapter in ListFragment activity.</p>

<p>Here is my code:</p>

<pre><code>private List&lt;Music&gt; musicList;
public View inflate;
ListView searchList;
public class SearchFragment extends ListFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        context = getActivity().getApplicationContext();
        inflate = inflater.inflate(R.layout.search, container, false);
        musicList = new ArrayList&lt;Music&gt;();
        adapter = new CustomListAdapter(musicList, context);
        searchList.setAdapter(adapter);
}
</code></pre>

<p>I have a NullPointerException in the following code:</p>

<p>The error is at <code>searchList.setAdapter(adapter);</code> so i also try to change to adapter value from <code>new ArrayList&lt;Music&gt;()</code> to <code>new &lt;Music&gt;ArrayList()</code> but no luck.</p>

<p>My Music class looks like this:</p>

<pre><code>public class Music {
    private String title, thumbnail, duration, uri, waveform;
    private int likes, playbackCount;

    public Music() {
    }

    public Music(String name, String thumbnailUrl, int likes, String rating, int playbackCount) {
        this.title = name;
        this.thumbnail = thumbnail;
        this.likes = likes;
        this.duration = rating;
        this.playbackCount = playbackCount;
    }

    public String getTitle() {
        return title;
    }
    public void setTitle(String name) {
        this.title = name;
    }

    public String getThumbnail() {
        return thumbnail;
    }
    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }

    public int getLikes() {
        return likes;
    }
    public void setLikes(int likes) { this.likes = likes; }

    public String getDuration() {
        return duration;
    }
    public void setDuration(String duration) {
        this.duration = duration;
    }

    public int getPlayBackCount() {
        return playbackCount;
    }
    public void setPlayBackCount(int playbackCount) {
        this.playbackCount = playbackCount;
    }

    public String getUri() {
        return uri;
    }
    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getWaveform() {
        return waveform;
    }
    public void setWaveform(String waveform) {
        this.waveform = waveform;
    }
}
</code></pre>
