# When I call count() method on the org.springframework.data.repository.CrudRepository.count() , ElasticsearchRepository.count().... it throws NullPointerException

**URL:** https://discuss.elastic.co/t/when-i-call-count-method-on-the-org-springframework-data-repository-crudrepository-count-elasticsearchrepository-count-it-throws-nullpointerexception/44129
**Category:** Elasticsearch
**Created:** [March 11, 2016, 9:12am UTC](https://discuss.elastic.co/t/when-i-call-count-method-on-the-org-springframework-data-repository-crudrepository-count-elasticsearchrepository-count-it-throws-nullpointerexception/44129 "2016-03-11T09:12:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![prashanthrd](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@prashanthrd](https://discuss.elastic.co/u/prashanthrd)
#### Post date: [March 11, 2016, 9:12am UTC](https://discuss.elastic.co/t/when-i-call-count-method-on-the-org-springframework-data-repository-crudrepository-count-elasticsearchrepository-count-it-throws-nullpointerexception/44129/1 "2016-03-11T09:12:45Z")

</div>

I am using spring-data-elasticsearch apis. When I call count() method on the org.springframework.data.repository.CrudRepository.count() , ElasticsearchRepository.count().... it throws NullPointerException.. I checked elasticsearch is working. But still gettting this error. Please suggest what can be done..

I posted in Spring forums, but there is no repsonse.

Thanks in advance.

---

<div class="post-metadata">

### Author: ![prashanthrd](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@prashanthrd](https://discuss.elastic.co/u/prashanthrd)
#### Post date: [March 11, 2016, 9:16am UTC](https://discuss.elastic.co/t/when-i-call-count-method-on-the-org-springframework-data-repository-crudrepository-count-elasticsearchrepository-count-it-throws-nullpointerexception/44129/2 "2016-03-11T09:16:38Z")

</div>

When I use @Autowired like

@Autowired  
priavate SomeRepository someRepository;

someRepository.count() --\> throws nullPointerException

I saw that someRepository reference variable is having null value. How can I use it in my spring application.  
This is the interface I created. { interface SomeRepository extends ElasticsearchRepository\<\> {} }

Please suggest...

Thanks in advance...

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [March 14, 2016, 2:55pm UTC](https://discuss.elastic.co/t/when-i-call-count-method-on-the-org-springframework-data-repository-crudrepository-count-elasticsearchrepository-count-it-throws-nullpointerexception/44129/3 "2016-03-14T14:55:38Z")

</div>

I am sorry to say that but the issue is entirely unrelated to Elasticsearch. Your dependency on `someRepository` is not injected by Spring. You might want to check whether the respective packages are included in the classpath scan of Spring and that your repository is properly configured (for details see the [Spring data docs](http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#repositories.create-instances)).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:08pm UTC](https://discuss.elastic.co/t/when-i-call-count-method-on-the-org-springframework-data-repository-crudrepository-count-elasticsearchrepository-count-it-throws-nullpointerexception/44129/4 "2017-07-05T23:08:39Z")

</div>


