title: Exception in thread "main" java.lang.NullPointerException: No API environment is registered for this thread getCurrentAppId
body: <p><strong>Language</strong>: - Java 1.7 <br>
  <strong>Environment</strong>: - Eclipse IDE Kepler</p>
  
  <p><strong>Requirement</strong>: - It is regarding fetch data from java application. I have created a web application in GAE which is working fine. Now I want to my application code should run from main and retrieve the date stored in Data Store. Need to fetch data from core java application.</p>
  
  <pre><code>import java.util.List; 
  import com.google.appengine.api.datastore.Entity; 
  import com.google.appengine.api.datastore.PreparedQuery; 
  import com.google.appengine.api.datastore.Query; 
  import com.google.appengine.api.datastore.Query.FilterOperator; 
  import com.google.appengine.api.datastore.DatastoreService; 
  import com.google.appengine.api.datastore.DatastoreServiceFactory; 
  import com.google.appengine.api.datastore.FetchOptions; 
  
  public static void main(String[] args)
      {
          DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
          Query query = new Query("SMS").addSort("Date", Query.SortDirection.DESCENDING);
          List&lt;Entity&gt; customers =  datastore.prepare(query).asList(FetchOptions.Builder.withLimit(50));
  
          for(Entity e : customers){
  
              System.out.println("Service: - " + e.getProperty("Service") );
              System.out.println("UserName: - " + e.getProperty("UserName") );
              System.out.println("QueryString: - " + e.getProperty("QueryString") );
              System.out.println("EmailId: - " + e.getProperty("EmailId") );
              System.out.println("MobileHashFormat: - " + e.getProperty("MobileHashFormat") );
              System.out.println("Date: - " + e.getProperty("Date") );
              System.out.println("Status: - " + e.getProperty("Status") );
  
  
  
  
              }
          }
  </code></pre>
  
  <p><strong>Exception</strong>: - </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NullPointerException: No API environment is registered for this thread.
      at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppId(DatastoreApiHelper.java:86)
      at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppIdNamespace(DatastoreApiHelper.java:102)
      at com.google.appengine.api.datastore.Query.(Query.java:215)
      at com.google.appengine.api.datastore.Query.(Query.java:144)
      at serive.TestGAEFile.main(TestGAEFile.java:17)</p>
  </blockquote>