title: KafKa error java.nio.channels.UnresolvedAddressException
body: <p>I did Kafka test and it worked. but when I run the program at IDE, I got this error and don't know how to solve it. Can anyone help me? Thanks a lot! </p>
  
  <pre><code>public final class Constants {
      public static final String REDIS_SERVER = "localhost";
  
      public static final String KAFKA_SERVER = "localhost";
  
      public static final String KAFKA_ADDR = KAFKA_SERVER + ":9092";
  
      public static final String KAFKA_TOPICS = "recom1";
  
  }
  
  val Array(brokers, topics) = Array(Constants.KAFKA_ADDR, Constants.KAFKA_TOPICS)
  
  val sparkConf = new 
  SparkConf().setMaster("local[2]").setAppName("RealtimeRecommender")
  
  val ssc = new StreamingContext(sparkConf, Seconds(2))
  
  val topicsSet = topics.split(",").toSet
  
  val kafkaParams = Map[String, String]("metadata.broker.list" -&gt; brokers,"auto.offset.reset" -&gt; "smallest")
  
  val messages = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](ssc, kafkaParams, topicsSet)
  </code></pre>
  
  <p>I think the ip and hostname may not map at /etc/hosts, But there is already   127.0.0.1   localhost. Can anyone help me?</p>
  
  <p>This is the error:</p>
  
  <pre><code>Exception in thread "main" org.apache.spark.SparkException: java.nio.channels.UnresolvedAddressException
      at org.apache.spark.streaming.kafka.KafkaCluster$$anonfun$checkErrors$1.apply(KafkaCluster.scala:366)
      at org.apache.spark.streaming.kafka.KafkaCluster$$anonfun$checkErrors$1.apply(KafkaCluster.scala:366)
      at scala.util.Either.fold(Either.scala:97)
      at org.apache.spark.streaming.kafka.KafkaCluster$.checkErrors(KafkaCluster.scala:365)
      at org.apache.spark.streaming.kafka.KafkaUtils$.getFromOffsets(KafkaUtils.scala:222)
      at org.apache.spark.streaming.kafka.KafkaUtils$.createDirectStream(KafkaUtils.scala:484)
      at com.ssx.recom.realtime.RealtimeRecommender$.main(RealtimeRecommender.scala:26)
      at com.ssx.recom.realtime.RealtimeRecommender.main(RealtimeRecommender.scala)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  </code></pre>