# Got nullpointer exception when using transport client

**URL:** <https://discuss.elastic.co/t/got-nullpointer-exception-when-using-transport-client/6246>\
**Category:** Elasticsearch\
**Created:** [December 28, 2011, 7:21am UTC](https://discuss.elastic.co/t/got-nullpointer-exception-when-using-transport-client/6246 "2011-12-28T07:21:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://discuss.elastic.co/u/ian)\
**Post date:** [December 28, 2011, 7:21am UTC](https://discuss.elastic.co/t/got-nullpointer-exception-when-using-transport-client/6246/1 "2011-12-28T07:21:07Z")

</div>

hello

```
      Im new to es and tried to implement it in my project and I got

```

the error as

```
              TransportClient client = new TransportClient(s);
              client.addTransportAddress(new InetSocketTransportAddress(
                  "localhost",
                  9300)
           );

```

XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();  
for(String key:map.keySet())  
{  
docBuilder.field(key,map.get(key) );  
}

```
            docBuilder.endObject();

```

indexRreqBuild = client.prepareIndex(indexName, indexType).  
setConsistencyLevel(WriteConsistencyLevel.DEFAULT).  
setSource(docBuilder);

null pointer exception occurs at client.prepareIndex(indexName, indexType).  
line

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 28, 2011, 10:36am UTC](https://discuss.elastic.co/t/got-nullpointer-exception-when-using-transport-client/6246/2 "2011-12-28T10:36:25Z")

</div>

Can you gist the full stack trace?

On Wed, Dec 28, 2011 at 9:21 AM, Simi MA [simi.ma@algotree.com](mailto:simi.ma@algotree.com) wrote:

> hello
> 
> ```
> Im new to es and tried to implement it in my project and I got
> 
> ```
> 
> the error as
> 
> ```
> TransportClient client = new TransportClient(s);
> client.addTransportAddress(new
> 
> ```
> 
> InetSocketTransportAddress(  
> "localhost",  
> 9300)  
> );  
> XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();  
> for(String key:map.keySet())  
> {  
> docBuilder.field(key,map.get(key) );  
> }
> 
> ```
> docBuilder.endObject();
> 
> ```
> 
> indexRreqBuild = client.prepareIndex(indexName, indexType).  
> setConsistencyLevel(WriteConsistencyLevel.DEFAULT).  
> setSource(docBuilder);
> 
> null pointer exception occurs at client.prepareIndex(indexName,  
> indexType). line

---

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://discuss.elastic.co/u/ian)\
**Post date:** [December 28, 2011, 11:25am UTC](https://discuss.elastic.co/t/got-nullpointer-exception-when-using-transport-client/6246/3 "2011-12-28T11:25:49Z")

</div>

The gist is  
[https://gist.github.com/27c02d804dc64cf197b3](https://gist.github.com/27c02d804dc64cf197b3)

On Wed, Dec 28, 2011 at 5:36 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Can you gist the full stack trace?
> 
> On Wed, Dec 28, 2011 at 9:21 AM, Simi MA [simi.ma@algotree.com](mailto:simi.ma@algotree.com) wrote:
> 
> > hello
> > 
> > ```
> > Im new to es and tried to implement it in my project and I got
> > 
> > ```
> > 
> > the error as
> > 
> > ```
> > TransportClient client = new TransportClient(s);
> > client.addTransportAddress(new
> > 
> > ```
> > 
> > InetSocketTransportAddress(  
> > "localhost",  
> > 9300)  
> > );  
> > XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();  
> > for(String key:map.keySet())  
> > {  
> > docBuilder.field(key,map.get(key) );  
> > }
> > 
> > ```
> > docBuilder.endObject();
> > 
> > ```
> > 
> > indexRreqBuild = client.prepareIndex(indexName, indexType).  
> > setConsistencyLevel(WriteConsistencyLevel.DEFAULT).  
> > setSource(docBuilder);
> > 
> > null pointer exception occurs at client.prepareIndex(indexName,  
> > indexType). line

---

<div class="post-metadata">

**Author:** ![ian](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@ian](https://discuss.elastic.co/u/ian)\
**Post date:** [December 28, 2011, 11:39am UTC](https://discuss.elastic.co/t/got-nullpointer-exception-when-using-transport-client/6246/4 "2011-12-28T11:39:49Z")

</div>

Hello

I got where the exception is coming from and solved the problem . Thanx  
for your reply

On Wed, Dec 28, 2011 at 6:25 AM, Simi MA [simi.ma@algotree.com](mailto:simi.ma@algotree.com) wrote:

> The gist is  
> [https://gist.github.com/27c02d804dc64cf197b3](https://gist.github.com/27c02d804dc64cf197b3)
> 
> On Wed, Dec 28, 2011 at 5:36 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > Can you gist the full stack trace?
> > 
> > On Wed, Dec 28, 2011 at 9:21 AM, Simi MA [simi.ma@algotree.com](mailto:simi.ma@algotree.com) wrote:
> > 
> > > hello
> > > 
> > > ```
> > > Im new to es and tried to implement it in my project and I got
> > > 
> > > ```
> > > 
> > > the error as
> > > 
> > > ```
> > > TransportClient client = new TransportClient(s);
> > > client.addTransportAddress(new
> > > 
> > > ```
> > > 
> > > InetSocketTransportAddress(  
> > > "localhost",  
> > > 9300)  
> > > );  
> > > XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();  
> > > for(String key:map.keySet())  
> > > {  
> > > docBuilder.field(key,map.get(key) );  
> > > }
> > > 
> > > ```
> > > docBuilder.endObject();
> > > 
> > > ```
> > > 
> > > indexRreqBuild = client.prepareIndex(indexName, indexType).  
> > > setConsistencyLevel(WriteConsistencyLevel.DEFAULT).  
> > > setSource(docBuilder);
> > > 
> > > null pointer exception occurs at client.prepareIndex(indexName,  
> > > indexType). line

---

<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 6, 2017, 3:44am UTC](https://discuss.elastic.co/t/got-nullpointer-exception-when-using-transport-client/6246/5 "2017-07-06T03:44:15Z")

</div>


