Issue with changing the name of the cluster and the java API

So, I have successfully set up ElasticSearch on my local system. And following is the code which I am trying to implement, based on ES trasnport client client and index example.

    String myClusterName = "mycluster";

    Settings settings = Settings.settingsBuilder()
        .put("cluster.name", myClusterName).build();
    settings = Settings.settingsBuilder()
            .put("client.transport.sniff", true).build();

    Client myClient = TransportClient.builder().build()
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("172.29.3.24"), 9300));
    try {
    IndexResponse clientresponse = myClient.prepareIndex("twitter", "tweet", "1")
        .setSource(jsonBuilder()
        .startObject()
        .field("user", "kimchy")
        .field("postDate", new Date())
        .field("message", "trying out Elasticsearch")
        .endObject()
        )
        .get();
    } catch (IOException e) {
	e.printStackTrace();
}

However when I am trying to run the example, I am getting the following error,

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{172.29.3.24}{172.29.3.24:9300}]]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207)
    at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:359)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56)
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:64)

The fun part is, if I start the cluster with the name elasticsearch and use the same in the code, the code works fine. It only creates trouble when I try to use a customized cluster name. Any thoughts as to why this happens?

I have found the problem.... Issue is resolved... I had not passed the "setting" which I had created before the transport builder... After passing the parameter as follows, the issue was resolved.

    Client myClient = TransportClient.builder().settings(setting).build()
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("172.29.3.24"), 9300));

Instead of:

Settings settings = Settings.settingsBuilder()
        .put("cluster.name", myClusterName).build();
    settings = Settings.settingsBuilder()
            .put("client.transport.sniff", true).build();

Write:

Settings settings = Settings.settingsBuilder()
        .put("cluster.name", myClusterName)
        .put("client.transport.sniff", true)
        .build();