Trying to template a post's image on an index page with a default image if it does not exist This is for an index page (again).  I want to list the 10 most recent articles.  There is a field postImage.  It is not required.  If it exists, I want to use postImage.  If not, I want to use a default image.

The relevant code is under the img tag.   

I get the following error:  Impossible to invoke a method ("getUrl") on a null variable..  I can verify that 7 of the first 10 entries do have a postImage.  


  {% for item in craft.entries.section('posts').limit(10) %}
                              {% set pic = item.postImage.one().getUrl() %}
                              {% if loop.index is divisible by(2) %}


                        &lt;div class="card card-plain card-blog"&gt;
                            &lt;div class="row"&gt;
                                &lt;div class="col-md-5"&gt;
                                    &lt;div class="card-header card-header-image"&gt;
                                        &lt;a href="#pablito"&gt;

                                            &lt;img class="img img-raised" src="{% if pic %}{{ pic }}{% else %}assets/img/office2.jpg
                                                {% endif %}
                                            "&gt;    

                                        &lt;/a&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;
                                &lt;div class="col-md-7"&gt;
                                    &lt;h6 class="card-category text-info"&gt;Enterprise&lt;/h6&gt;
                                    &lt;h3 class="card-title"&gt;
                                        &lt;a href="{{ item.url }}"&gt;{{ item.title }}&lt;/a&gt;
                                    &lt;/h3&gt;
                                    &lt;p class="card-description"&gt;
                                       {{ item.introParagraph }}
                                        &lt;a href="{{ item.url }}"&gt; Read More &lt;/a&gt;
                                    &lt;/p&gt;
                                    &lt;p class="author"&gt;
                                        by
                                        &lt;a href=""&gt;
                                            &lt;b&gt;x&lt;/b&gt;
                                        &lt;/a&gt;, 2 days ago
                                    &lt;/p&gt;
                                &lt;/div&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;

                        {% else %}


There are 2 if / else statements.   Only the 1 associated with the img tag is relevant.

Thanks.
Drop the getUrl() from the set and everything works.