Can't use getLayoutInflater() in Android
<p>If my code <code>extends AppCompatActivity</code>:</p>

<pre><code>View uploadProgressView = getLayoutInflater().inflate(R.layout.view_upload_progress, null);
UploadProgressViewHolder viewHolder = new UploadProgressViewHolder(uploadProgressView, filename);
</code></pre>

<p>I can use <code>getLayoutInflater()</code> but when I change to <code>extends Services</code> it is not working.</p>

<p>I was research on <code>Stackoverflow</code> <a href="https://stackoverflow.com/questions/7803771/call-to-getlayoutinflater-in-places-not-in-activity">from this post</a> and receive answer and change to:</p>

<pre><code>LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View uploadProgressView = inflater.inflate(R.layout.view_upload_progress, null);
UploadProgressViewHolder viewHolder = new UploadProgressViewHolder(uploadProgressView, filename);
</code></pre>

<p>But it is not working, how to use <code>getLayoutInflater()</code>?</p>

<p>This throw exception:
<code>java.lang.NullPointerException</code></p>

<p>CallRecordService.addUploadToList(CallRecordService.java:167)
Error at first line <code>LayoutInflater inflater = ......</code></p>

<pre><code>Context context;
private void addUploadToList(String uploadID, String filename) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
    View uploadProgressView = inflater.inflate(R.layout.view_upload_progress, null);
    UploadProgressViewHolder viewHolder = new UploadProgressViewHolder(uploadProgressView, filename);
    viewHolder.uploadId = uploadID;
    container.addView(viewHolder.itemView, 0);
    uploadProgressHolders.put(uploadID, viewHolder);
}
</code></pre>