public class PrimeMapper extends Mapper<LongWritable,IntWritable,IntWritable,NullWritable>
{
public void map(LongWritable k,IntWritable val,Context c) throws IOException, InterruptedException
{
int v=val.get();
int i=2;
if(v==1)
c.write(new IntWritable(v), NullWritable.get());
for(i=2;i<v;i++)
{
if(v%i==0)
break;
}
if(v==i)
c.write(new IntWritable(v),NullWritable.get());
}
}
当我试图运行这段代码时,我得到了一个类型转换错误的错误。
1条答案
按热度按时间toe950271#
使用默认输入格式textinputformat(extends)时
FileInputFormat<LongWritable, Text>
),Map程序期望LongWritable
作为key
以及Text
作为value
. 如果在程序中没有显式更改,则Map器定义不正确。正确的实现如下所示: