在编写mapreduce类时

bnlyeluc  于 2021-05-27  发布在  Hadoop
关注(0)|答案(1)|浏览(401)

我在编译平均温度代码时遇到了这个错误。它给了我以下的错误。

hduser@ubuntu:/home/sara/Desktop/MaxTemp$ javac -classpath 
      $HADOOP_HOME/share/hadoop/common/hadoop-common- 
     2.7.2.jar:$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client- 
    core-2.7.2.jar:$HADOOP_HOME/share/hadoop/common/lib/commons-cli-1.2.jar 
    -d '/home/sara/Desktop/MaxTemp' *.java 
      AverageDriver.java:17: error: error while writing AvgMaxTemp: 
      /home/sara/Desktop/MaxTemp/AverageDriver$AvgMaxTemp.class
      public static class AvgMaxTemp extends Mapper<Object, Text, Text, 
          IntWritable>{
          ^
        1 error

csv文件,我正在使用它来获取数据

代码是

public class AverageDriver {
     public static class AvgMaxTempM extends Mapper<Object, Text, Text, 
      IntWritable>{

       private IntWritable TmaxValue = new IntWritable();
        private Text Value = new Text();

      public void map(Object key, Text value, Context con) throws 
      IOException, InterruptedException
        {
     String line = value.toString();
     String[] words = line.split(",");
      TmaxValue.set(Integer.parseInt(words[2]));
      Value.set(words[3]);
       if(words[2].equals("TMAX")){  

       for(String word: words )
      {
    con.write( Value , TmaxValue );
       }

      } } }
   public class AveragemaxTempR extends Reducer< Text, IntWritable,Text, 
   IntWritable >
    {
          public void reduce(Text key,  Iterable<IntWritable> values, 
        Context 
        context) throws IOException,                                                       
      InterruptedException
        {          
        int max_temp = 0; 
        int count = 0;
        for (IntWritable value : values)
                    {
                                max_temp += value.get();     
                                count+=1;
                    }
        context.write(key, new IntWritable(max_temp/count));
        }                                             
          }
8iwquhpp

8iwquhpp1#

驱动程序类中有一个静态类引发编译错误:

public class AverageDriver {
 public static class AvgMaxTempM extends Mapper<Object, Text, Text, 
  IntWritable>{

您使用的是intellij或eclipse之类的ide吗?它可以帮助格式化您的代码,还可以在编译之前识别类似的问题。

相关问题