Explore Courses Blog Tutorials Interview Questions
0 votes
in Big Data Hadoop & Spark by (11.4k points)

When I am running a Hadoop .jar file from the command prompt, it throws an exception saying no such method StockKey method.

StockKey is my custom class defined for my own type of key.

Here is the exception:

12/07/12 00:18:47 INFO mapred.JobClient: Task Id :  
attempt_201207082224_0007_m_000000_1, Status : FAILED

java.lang.RuntimeException: java.lang.NoSuchMethodException: SecondarySort$StockKey.     
    at org.apache.hadoop.util.ReflectionUtils.newInstance(
    at org.apache.hadoop.mapred.JobConf.getOutputKeyComparator(
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.<init>(
    at org.apache.hadoop.mapred.MapTask.runOldMapper(
    at org.apache.hadoop.mapred.Child$
    at Method)
    at org.apache.hadoop.mapred.Child.main(

1 Answer

0 votes
by (32.3k points)
edited by

In your program, Hadoop is using reflection and it can not guess any parameters to feed.

You should provide an empty default constructor in your key class. 

So just add the default constructor:

public StockKey(){}


Whenever you get errors like this for classes which are writable, mappers, reducers, etc.

If the class is an inner class, and not defined as static, then first make them static.

In your code Mapper and reducer, classes need to be defined statically.

public static class MaxTemperatureMapper extends Mapper<....

public static class MaxTemperatureReducer extends Reducer<....

If you want more knowledge regarding Hadoop, refer to the following video:


Related questions

Browse Categories