在putty上运行此代码时,出现以下错误:
线程“main”java.langj中的mapreduce异常avascript:void(0).未找到类exception:gameratings.java
我不知道该怎么办。我也不确定它是否能找到以前工作时的平均数。我试着运行它,但Map器失败了。
我该怎么修?
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class GameRatings {
public static class mapper extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context) throws
IOException, InterruptedException {
Text publisher = new Text();
IntWritable gameRating = new IntWritable();
String line;
Text gameName = new Text();
StringTokenizer itr = new StringTokenizer(value.toString(),"\n");
while (itr.hasMoreTokens()) {
line = itr.nextToken();
line.split("\t");
gameName.set(itr.nextToken());
publisher.set(itr.nextToken());
gameRating.set(Integer.parseInt(itr.nextToken()));
context.write(publisher,gameRating);
}
}
}
public static class reducer extends Reducer<IntWritable, Text, IntWritable,
Text> {
public void reduce(IntWritable key, Iterable<Text> values, Context context,
OutputCollector<Text, IntWritable> output) throws IOException,
InterruptedException {
char gameRating = ' ';
int sum = 0;
int gameCount = 0;
int avgRating = 0;
for (Text value : values) {
sum += value.get();
gameCount+=1;
String[] tokens = value.toString().split("\t");
}
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "Average rating");
job.setJarByClass(GameRatings.class);
job.setMapperClass(mapper.class);
job.setCombinerClass(reducer.class);
job.setReducerClass(reducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!