title: submit spark job from java code and get java.lang.NullPointerException
body: <p>I want to submit spark job to yarn cluster, and I get the reference from  "<a href="https://github.com/mahmoudparsian/data-algorithms-book/blob/master/misc/how-to-submit-spark-job-to-yarn-from-java-code.md" rel="nofollow">https://github.com/mahmoudparsian/data-algorithms-book/blob/master/misc/how-to-submit-spark-job-to-yarn-from-java-code.md</a>".</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package learn.spark;
  
  import org.apache.spark.deploy.yarn.Client;
  import org.apache.spark.deploy.yarn.ClientArguments;
  import org.apache.hadoop.conf.Configuration;
  import org.apache.spark.SparkConf;
  
  public class SubmitJob {
  
  public static void main(String[] arguments) throws Exception {
  
      String[] args = new String[] {
  
          "--jar", "lib/spark-examples-1.4.0-hadoop2.6.0.jar",
          "--class", "org.apache.spark.examples.mllib.JavaKMeans",
          "--num-executors", "32",
          "--executor-cores", "4",
          "--executor-memory", "16G", 
          "--driver-memory", "8G",    
          "--addJars", "./lib/spark-assembly-1.4.0-hadoop2.6.0.jar",
  
          "--arg", "/data/kmeans_data.txt",
          "--arg", "5",
          "--arg", "9"    
      };
  
      Configuration config = new Configuration();
  
      System.setProperty("SPARK_YARN_MODE", "true");
  
      SparkConf sparkConf = new SparkConf();
  
      ClientArguments cArgs = new ClientArguments(args, sparkConf); 
  
      Client client = new Client(cArgs, config, sparkConf); 
  
      client.run(); 
  }
  }
  </code></pre>
  
  <p>I compile the source and jar. running the program by the follow cmd:</p>
  
  <pre><code>java -Xbootclasspath/a:./lib/spark-assembly-1.4.0-hadoop2.6.0.jar: -jar learn.spark.SubmitJob.jar
  </code></pre>
  
  <p>Unluckly, I got the follow error:
  <a href="http://i.stack.imgur.com/Mlvcc.png" rel="nofollow">The output</a></p>
  
  <p>I can't understand the problem, or How can I submit a spark job to yarn cluster? 
  Is there a better way?</p>