title: Hadoop word count example - null pointer exception
body: <p>I'm Hadoop beginner. My setup: RHEL7, hadoop-2.7.3 </p>
  
  <p>I'm trying to run the <a href="https://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html#Example:_WordCount_v2.0" rel="nofollow">Example:_WordCount_v2.0</a>. I just copied the source code to new eclipse project and export it to wc.jar file.</p>
  
  <p>Now, I've configured hadoop <a href="https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/SingleCluster.html#Pseudo-Distributed_Operation" rel="nofollow">Pseudo-Distributed Operation</a> as explianed in the link. Then I start by the following:</p>
  
  <p>creating input files in input directory:</p>
  
  <pre><code>echo "Hello World, Bye World!" &gt; input/file01
  echo "Hello Hadoop, Goodbye to hadoop." &gt; input/file02
  </code></pre>
  
  <p>start env:</p>
  
  <pre><code>sbin/start-dfs.sh
  bin/hdfs dfs -mkdir /user
  bin/hdfs dfs -mkdir /user/&lt;username&gt;
  bin/hdfs dfs -put input input
  bin/hadoop jar ws.jar WordCount2 input output
  </code></pre>
  
  <p>and this is what I got:</p>
  
  <pre><code>16/09/02 13:15:01 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
  16/09/02 13:15:01 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
  16/09/02 13:15:01 INFO input.FileInputFormat: Total input paths to process : 2
  16/09/02 13:15:01 INFO mapreduce.JobSubmitter: number of splits:2
  16/09/02 13:15:01 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local455553963_0001
  16/09/02 13:15:01 INFO mapreduce.Job: The url to track the job: http://localhost:8080/
  16/09/02 13:15:01 INFO mapreduce.Job: Running job: job_local455553963_0001
  16/09/02 13:15:01 INFO mapred.LocalJobRunner: OutputCommitter set in config null
  16/09/02 13:15:01 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
  16/09/02 13:15:01 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
  16/09/02 13:15:02 INFO mapred.LocalJobRunner: Waiting for map tasks
  16/09/02 13:15:02 INFO mapred.LocalJobRunner: Starting task: attempt_local455553963_0001_m_000000_0
  16/09/02 13:15:02 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
  16/09/02 13:15:02 INFO mapred.Task:  Using ResourceCalculatorProcessTree : [ ]
  16/09/02 13:15:02 INFO mapred.MapTask: Processing split: hdfs://localhost:9000/user/aii/input/file02:0+33
  16/09/02 13:15:02 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)
  16/09/02 13:15:02 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100
  16/09/02 13:15:02 INFO mapred.MapTask: soft limit at 83886080
  16/09/02 13:15:02 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600
  16/09/02 13:15:02 INFO mapred.MapTask: kvstart = 26214396; length = 6553600
  16/09/02 13:15:02 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
  16/09/02 13:15:02 INFO mapred.MapTask: Starting flush of map output
  16/09/02 13:15:02 INFO mapred.LocalJobRunner: Starting task: attempt_local455553963_0001_m_000001_0
  16/09/02 13:15:02 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
  16/09/02 13:15:02 INFO mapred.Task:  Using ResourceCalculatorProcessTree : [ ]
  16/09/02 13:15:02 INFO mapred.MapTask: Processing split: hdfs://localhost:9000/user/aii/input/file01:0+24
  16/09/02 13:15:02 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)
  16/09/02 13:15:02 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100
  16/09/02 13:15:02 INFO mapred.MapTask: soft limit at 83886080
  16/09/02 13:15:02 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600
  16/09/02 13:15:02 INFO mapred.MapTask: kvstart = 26214396; length = 6553600
  16/09/02 13:15:02 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
  16/09/02 13:15:02 INFO mapred.MapTask: Starting flush of map output
  16/09/02 13:15:02 INFO mapred.LocalJobRunner: map task executor complete.
  16/09/02 13:15:02 WARN mapred.LocalJobRunner: job_local455553963_0001
  java.lang.Exception: java.lang.NullPointerException
      at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
      at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
  Caused by: java.lang.NullPointerException
      at WordCount2$TokenizerMapper.setup(WordCount2.java:47)
      at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:143)
      at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787)
      at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
      at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:243)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  16/09/02 13:15:02 INFO mapreduce.Job: Job job_local455553963_0001 running in uber mode : false
  16/09/02 13:15:02 INFO mapreduce.Job:  map 0% reduce 0%
  16/09/02 13:15:02 INFO mapreduce.Job: Job job_local455553963_0001 failed with state FAILED due to: NA
  16/09/02 13:15:02 INFO mapreduce.Job: Counters: 0
  </code></pre>
  
  <p>No results (output) was given. Why did I get that exception?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks to solutions suggested I've realized that there is a second try (in the wordCount example):</p>
  
  <pre><code>echo "\." &gt; patterns.txt
  echo "\," &gt;&gt; patterns.txt
  echo "\!" &gt;&gt; patterns.txt
  echo "to" &gt;&gt; patterns.txt
  </code></pre>
  
  <p>and then run:</p>
  
  <pre><code>bin/hadoop jar ws.jar WordCount2 -Dwordcount.case.sensitive=true input output -skip patterns.txt
  </code></pre>
  
  <p>and everything is work great!</p>