Hadoop: No Such Method Exception

0 votes

My MapReduce code is as follows:

import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class MaxTemperature {

public class MaxTemperatureMapper extends Mapper <LongWritable, Text, Text, IntWritable>{
    private static final int MISSING = 9999;

    public void map(LongWritable key, Text Value, Context context, Reporter reporter) throws IOException, InterruptedException{
        String line = Value.toString();
        String year = line.substring(15,19);
        int airTemperature;
            airTemperature = Integer.parseInt(line.substring(88,92));
            airTemperature = Integer.parseInt(line.substring(87,91));
        String quality = line.substring(92,93);
        if(airTemperature!=MISSING && quality.matches("[01459]"))
            context.write(new Text(year), new IntWritable(airTemperature));

public class MaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable>{
    public void reduce (Text Key, Iterator<IntWritable> Values, Context context, Reporter reporter) throws IOException, InterruptedException{

        int maxValue = Integer.MIN_VALUE;
            maxValue = Math.max(maxValue, Values.next().get());
        context.write(Key, new IntWritable(maxValue));


public static void main(String[] args) throws Exception {
        System.err.println("Usage: WeatherTemperature  <input path> <output path>");
    Configuration conf = new Configuration();
    Job job = new Job(conf, "Maximum Temperature Calculator");



//  job.setInputFormatClass(TextInputFormat.class);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

I run the .jar of this program using the following command:

hadoop jar weather.jar MaxTemperature input output

And I'm getting the following error:

12/06/13 00:52:05 INFO mapred.JobClient: Task Id :     attempt_201206121354_0007_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.NoSuchMethodException:      MaxTemperature$MaxTemperatureMapper.<init>()
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:602)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:323)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:270)
    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:1177)
    at org.apache.hadoop.mapred.Child.main(Child.java:264)
Caused by: java.lang.NoSuchMethodException: MaxTemperature$MaxTemperatureMapper.<init>()
    at java.lang.Class.getConstructor0(Class.java:2706)
    at java.lang.Class.getDeclaredConstructor(Class.java:1985)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:109)
    ... 7 more

please help

Oct 26, 2018 in Big Data Hadoop by slayer
• 29,300 points

recategorized Oct 26, 2018 by Omkar 553 views

1 answer to this question.

0 votes

Mapper and reducer classes need to be defined static.

public static class MaxTemperatureMapper extends Mapper<....

public static class MaxTemperatureReducer extends Reducer<....
answered Oct 26, 2018 by Omkar
• 69,030 points

Related Questions In Big Data Hadoop

0 votes
1 answer

“no such file or directory" in case of hadoop fs -ls

The behaviour that you are seeing is ...READ MORE

answered May 9, 2018 in Big Data Hadoop by nitinrawat895
• 10,950 points

edited May 9, 2018 by nitinrawat895 4,663 views
0 votes
1 answer

Hadoop Pipe: shared libraries, No such file or directory error

Add -rpath my.zip/lib to LDFLAGS_HDP. For compilation to work, you ...READ MORE

answered Aug 30, 2018 in Big Data Hadoop by Frankie
• 9,810 points
0 votes
1 answer
0 votes
1 answer

Hadoop: Error: slave: bash: line 0: cd: /opt/hadoop-1.1.0/libexec/..: No such file or directory

Hi,   In this case, it is searching ...READ MORE

answered Aug 7, 2019 in Big Data Hadoop by Gitika
• 41,360 points
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,950 points
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,950 points
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyF ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
–1 vote
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,320 points
0 votes
1 answer

Hadoop: `.' no such file or directory while installing

Try hadoop fs -mkdir -p /user/[Username] and then run ...READ MORE

answered Nov 2, 2018 in Big Data Hadoop by Omkar
• 69,030 points
+1 vote
1 answer

bash: sbin/hadoop: No such file or directory

The hadoop command is not present in ...READ MORE

answered Sep 18, 2019 in Big Data Hadoop by Omkar
• 69,030 points