title: Hadoop job fails while reducing, Java.io.IOException: Type mismatch in value from map
body: <p>My <code>Map</code> class is </p>
  
  <pre><code> public static class MapClass extends Mapper&lt;LongWritable, Text, Text, LongWritable&gt; {
  
          public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
              // your map code goes here
              String[] fields = value.toString().split(",");
              String year = fields[1];
              String claims = fields[8];
  
              if (claims.length() &gt; 0 &amp;&amp; (!claims.startsWith("\""))) {
                  context.write(new Text(year), new LongWritable(Long.parseLong(claims)));
              }
          }
      }
  </code></pre>
  
  <p>My <code>Reduce</code> class Looks like</p>
  
  <pre><code>   public static class Reduce extends Reducer&lt;Text, LongWritable, Text, Text&gt; {
  
  
          public void reduce(Text key, Iterable&lt;LongWritable&gt; values, Context context) throws IOException, InterruptedException {
              // your reduce function goes here
              context.write(key, new Text("hello"));
          }
      }
  </code></pre>
  
  <p>The dataset looks like</p>
  
  <pre><code>3070801,1963,1096,,"BE","",,1,,269,6,69,,1,,0,,,,,,,
  3070802,1963,1096,,"US","TX",,1,,2,6,63,,0,,,,,,,,, 
  </code></pre>
  
  <p>When I run program with configuration</p>
  
  <pre><code>        Job job = new Job();
          job.setJarByClass(TopKRecords.class);
  
          job.setMapperClass(MapClass.class);
          job.setReducerClass(Reduce.class);
  
          FileInputFormat.setInputPaths(job, new Path(args[0]));
          FileOutputFormat.setOutputPath(job, new Path(args[1]));
  
          job.setJobName("TopKRecords");
          job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(Text.class);
  </code></pre>
  
  <p>I see error as  </p>
  
  <pre><code>java.io.IOException: Type mismatch in value from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable
      at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1019)
      at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:691)
      at org.apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80)
      at com.hadoop.programs.TopKRecords$MapClass.map(TopKRecords.java:35)
      at com.hadoop.programs.TopKRecords$MapClass.map(TopKRecords.java:26)
      at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
      at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
      at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
      at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:396)
      at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
      at org.apache.hadoop.mapred.Child.main(Child.java:249)
  </code></pre>
  
  <p>What is wrong going here?</p>
  
  <p>I dont see any reason for mismatch here</p>
  
  <pre><code>Mapper&lt;LongWritable, Text, Text, LongWritable&gt;
  Reducer&lt;Text, LongWritable, Text, Text&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After setting the following, things started to work</p>
  
  <pre><code>        job.setMapOutputKeyClass(Text.class);
          job.setMapOutputValueClass(LongWritable.class);
  </code></pre>