Got nullpointer exception when using transport client


(ian) #1

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


(Shay Banon) #2

Can you gist the full stack trace?

On Wed, Dec 28, 2011 at 9:21 AM, Simi MA 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


(ian) #3

The gist is
https://gist.github.com/27c02d804dc64cf197b3

On Wed, Dec 28, 2011 at 5:36 AM, Shay Banon 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 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


(ian) #4

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 wrote:

The gist is
https://gist.github.com/27c02d804dc64cf197b3

On Wed, Dec 28, 2011 at 5:36 AM, Shay Banon 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 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


(system) #5