Ich programmiere gerade ein kleines MapReduce-Programm.
Jetzt habe ich hier so einen Anfängerfehler, der mich schon 2h festhält. Was mache ich falsch?
Ausgabe
Wenn ich das import rausnehme sagt er cannot find symbol.
Die beiden Klassen liegen in einem Ordner. Classpath dürfte doch hier keine rolle spielen, oder?? Die Dateien haben auch exakt den gleichen Namen die die Klassen, nämlich ex4_3b.java und City.java.
Jetzt habe ich hier so einen Anfängerfehler, der mich schon 2h festhält. Was mache ich falsch?
Java:
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
import City;
public class ex4_3b {
City city;
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line, "|");
Text[] raw = new Text[6];
int count = 0;
while (tokenizer.hasMoreTokens()) {
raw[count].set(tokenizer.nextToken());
count++;
}
//city = new City(raw[0], raw[1], raw[2], (IntWritable)Integer.parseInt(raw[3]), (FloatWritable)Float.parseFloat(raw[4]), (FloatWritable)Float.parseFloat(raw[5]));
output.collect(raw[0], city);
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(ex4_3b.class);
conf.setJobName("ex4_3b");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
Java:
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.IntWritableWritable;
import org.apache.hadoop.io.FloatWritableWritable;
public class City {
private final Text name;
private final Text country;
private final Text province;
private final IntWritable population;
private final FloatWritable longitude;
private final FloatWritable latitude;
public City(Text n, Text c, Text p, IntWritable pop, FloatWritable longi, FloatWritable lat){
name = n;
country = c;
province = p;
population = pop;
longitude = longi;
latitude = lat;
}
public IntWritable getPop(){
return population;
}
}
Ausgabe
Code:
ex4_3b.java:18: '.' expected
import City;
^
ex4_3b.java:18: ';' expected
import City;
Wenn ich das import rausnehme sagt er cannot find symbol.
Die beiden Klassen liegen in einem Ordner. Classpath dürfte doch hier keine rolle spielen, oder?? Die Dateien haben auch exakt den gleichen Namen die die Klassen, nämlich ex4_3b.java und City.java.
Zuletzt bearbeitet von einem Moderator: