错误:java hadoop 中需要 <identifier>

Posted

技术标签:

【中文标题】错误:java hadoop 中需要 <identifier>【英文标题】:error: <identifier> expected in java hadoop 【发布时间】:2017-09-09 00:10:16 【问题描述】:

我正在编译一个用于字数统计 hadoop 的 java 文件,但是在编译时会引发错误:

CountBook.java:33: 错误:预期的 public void reduce(Text_key,Iteratorvalues,OutputCollectoroutput,Reporter report)throw IOException

这是我的代码

public class CountBook

    public static class EMapper extends MapReducebase implements
    Mapper<LongWritable,Text,Text,IntWritable>
    
        private final static Intwritable one = new Intwritable(1);
        public void map(LongWritable key,Text value,OutputCollector<Text,IntWritable>output,Reporter reporter)throws IOException
        
            String line = value.toString();
            String[] Data = line.split("\";\"");
            output.collect(new text(Data[0]),one);

        
    


public static class EReduce extends MapReduceBase implements
Reducer<Text,IntWritable,Text,IntWritable>

    public void reduce(Text_key,Iterator<IntWritable>values,OutputCollector<text,intWritable>output,Reporter reporter)throws IOException
    
        Text key=_key;
        int authid=0;
        while(values.hasNext())
        
            IntWritable value = (IntWritable)values.next();
            authid+=value.get();
        
        output.collect(key,new intWritable(authid));
    



public static void main(String args[])throws Exception

    JobConf conf = new JbConf(CountBook.class);
    conf.setjobName("CountBookByAuthor");
    conf.setOutputkeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);
    conf.setMapperClass(EMapper.class);
    conf.setCombinerClass(EReduce.class);
    conf.setReducerClass(EReducer.class);
    conf.setOutputFormat(TextOutputFormat.class);
    FileInputFormat.setInputPaths(conf,new path(args[0]));
    FileOutputFormat.setOutputPath(conf,new Path(args[1]));
    JobCLient.runJob(conf);


我正在使用 hadoop-core-1.2.1.jar 作为类路径库并在 centos 7 中运行

【问题讨论】:

看起来您正试图在公共类中嵌入公共 lasses - 不能这样做,因为每个公共类都需要在自己的文件中 【参考方案1】:

您目前拥有:

reduce(Text_key, 
       Iterator<IntWritable>values,
       OutputCollector<text,intWritable>output, 
       Reporter reporter)

应该是:

reduce(Text key, 
       Iterator<IntWritable> values,
       OutputCollector<Text,IntWritable> output, 
       Reporter reporter)

主要区别在于keyText 之间需要一个空格,并且OutputCollector&lt;&gt; 中的类型需要大写。

【讨论】:

以上是关于错误:java hadoop 中需要 <identifier>的主要内容,如果未能解决你的问题,请参考以下文章

Hadoop Hive 查询中 IN 子句中的大量 Id

hadoop在往HDFS中写数据的时候报错,错误信息如下,请大神指导

在运行JAVA程序时出错,大家帮看一下是怎么回事,最好懂hadoop编程~~

Hadoop集群搭建之SSH无密码登录配置错误解析

java程序中的编译错误以使用hadoop计算文件中的单词

hadoop错误FATAL org.apache.hadoop.hdfs.server.namenode.NameNode Exception in namenode join java.io.IOE