Displaying Snackbar from Utility class
<p>I am trying to display a <code>SnackBar</code> when an exception is thrown in my utility class.  </p>

<p><strong>Utils.class</strong></p>

<pre><code>    public class Utils {

  private static String LOG_TAG = Utils.class.getSimpleName();

  public static boolean showPercent = true;

  public static ArrayList quoteJsonToContentVals(String JSON){
    ArrayList&lt;ContentProviderOperation&gt; batchOperations = new ArrayList&lt;&gt;();
    JSONObject jsonObject = null;
    JSONArray resultsArray = null;
    try{
      jsonObject = new JSONObject(JSON);
      if (jsonObject != null &amp;&amp; jsonObject.length() != 0){
        jsonObject = jsonObject.getJSONObject("query");
        int count = Integer.parseInt(jsonObject.getString("count"));
        if (count == 1){
          jsonObject = jsonObject.getJSONObject("results")
              .getJSONObject("quote");
          batchOperations.add(buildBatchOperation(jsonObject));
        } else{
          resultsArray = jsonObject.getJSONObject("results").getJSONArray("quote");

          if (resultsArray != null &amp;&amp; resultsArray.length() != 0){
            for (int i = 0; i &lt; resultsArray.length(); i++){
              jsonObject = resultsArray.getJSONObject(i);
              batchOperations.add(buildBatchOperation(jsonObject));
            }
          }
        }
      }
    } catch (Exception e)
    {
      runError();  // &lt;-- The method that displays the Snackbar
    }
    return batchOperations;
  }
</code></pre>

<p>And, now here is the method that tries to display the <code>SnackBar</code>:</p>

<pre><code>  private static void runError()
  {

    Snackbar.make(this.findViewById(android.R.id.content), "OOPS that's an error :/", Snackbar.LENGTH_LONG).show();
  }
</code></pre>

<p>Now, the problem is : I am unable to get <code>context</code> to call <code>SnackBar</code>. I tried replacing <code>this</code> with:</p>

<ul>
<li><code>getContext()</code></li>
<li><code>getActivity()</code></li>
<li><code>getApplicationContext()</code></li>
</ul>

<p>Since none of this did work, I tried creating an Application class to get context globally. </p>

<pre><code>    public class StockMain extends Application
{
    private static StockMain instance;

    public static StockMain getInstance() {
        return instance;
    }

    public static Context getContext(){
        return instance;
        // or return instance.getApplicationContext();
    }

    @Override
    public void onCreate() {
        instance = this;
        super.onCreate();
    }
}
</code></pre>

<p>And tried changing, the method <code>runError()</code> to : </p>

<pre><code>     private static void runError()
  {

    Snackbar.make(StockMain.getContext().findViewById(android.R.id.content), "OOPS that's an error :/", Snackbar.LENGTH_LONG).show();
  }
</code></pre>

<p>Unfortunately, that did not work as well! 
So, how to fix this issue? </p>