Q:

MapReduce with Hadoop: Type mismatch

I'm running a simple hadoop program, and I get the following error:
java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable

Mapper:
public static class myMapper extends Mapper<LongWritable, Text, Text, Text>
public void map(LongWritable key, Text line,OutputCollector<Text,Text> output, Reporter reporter) throws IOException, InterruptedException

Reducer:
public static class triangleCounterReducer extends Reducer<Text, Text, Text, Text> 
public void reduce(Text key,Iterable<Text> line,OutputCollector<Text,Text> output,Reporter reporter) throws IOException, InterruptedException

Main:
...
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
...

How can i fix this????

A:

Looks like your using the new API classes (you mapper extends mapred.Mapper), but you have written your map method using the old API (you are using OutputCollector and Reporter)
Change your mapper map signature and reducer reduce method to the following:
public void map(LongWritable key, Text value, Context context) { .. }
public void reduce(Text key, Iterable<Text> value, Context context) { .. }

It also helps if you add the @Override annotation above the methods, which will cause the compiler to fail if you have the wrong signature.

