title: Callback from Adapter
body: <p>So I have a custom listview. It's like Instagram layout with 1 image and bunch of buttons in each list items. So here's the problem:</p>
  
  <p>I want to implement the share button. To do this, I tried to create a callback from adapter to activity. But it didn't seem to work. Here is what I have so far(I cropped out the unrelated parts):</p>
  
  <blockquote>
    <p>MainActivity</p>
  </blockquote>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements ListAdapter.OnShareClickedListener{
  
      ListView main_list;
      List&lt;String&gt; url_list; 
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          main_list = (ListView) findViewById(R.id.listView);
          ListAdapter nListAdapter = new ListAdapter(context, url_list);
          main_list.setAdapter(nListAdapter);
      }
  
      @Override
      public void ShareClicked(String url) {
          Log.e("Test",url);
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>ListAdapter</p>
  </blockquote>
  
  <pre><code>public class ListAdapter extends BaseAdapter implements View.OnClickListener {
  
      OnShareClickedListener mCallback;
      Context context;
      public static List&lt;String&gt; url_list;
  
      public ListAdapter(Context c, List&lt;String&gt; list) {
          this.context = c;
          url_list = list;
      }
  
      public interface OnShareClickedListener {
          public void ShareClicked(String url);
      }
  
  
      @Override
      public void onClick(View v) {
                  mCallback.ShareClicked("Share this text.");
          }
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>Error Log:</p>
  </blockquote>
  
  <pre><code>Attempt to invoke interface method 'void com.packagename.ListAdapter$OnShareClickedListener.ShareClicked(java.lang.String)' on a null object reference
  </code></pre>