title: Calling " getContentResolver " in an Android Java class
body: <p>I have an Service S which contains a Thread T. I also have a Java Class C. I would like to call a method of the class C from the thread T. The method is supposed to contain the lines :</p>
  
  <pre><code>Uri uri = Uri.parse("content://sms");
  Cursor cursor1 =  getContentResolver().query(uri, null, null ,null, null);
  </code></pre>
  
  <p>The problem is that I get the error " 
  Cannot resolve the methode 'getContentResolver()' ".
  I know this is a matter of Context, but I don't know how to solve it.</p>
  
  <p>EDIT</p>
  
  <p>Without considering the thread T, tried this :</p>
  
  <p>The class C :</p>
  
  <pre><code>public class SMS {
  
  private ArrayList&lt;String&gt; smsList = new ArrayList&lt;&gt;();
  
  public SMS(Context context){        
  
      Uri uri = Uri.parse("content://sms");
      Cursor cursor1 =  context.getContentResolver().query(uri, null, null ,null, null);
  
      }
  }
  </code></pre>
  
  <p>The service S :</p>
  
  <pre><code>public class MyService extends Service{
  
      SMS sms = new SMS(this);
  }
  </code></pre>
  
  <p>But I get the error :</p>
  
  <pre><code>java.lang.NullPointerException
  at com.example.maxime.servicesms2.SMS.&lt;init&gt;(SMS.java:18)
  </code></pre>
  
  <p>Line 18 being :</p>
  
  <pre><code>Cursor cursor1 =  context.getContentResolver().query(uri, null, null ,null, null);
  </code></pre>
  
  <p>Thank you for your help !</p>