-1
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());
}
}
當我試圖運行此代碼我得到類型錯誤的錯誤。java.lang.Exception的:java.lang.ClassCastException:org.apache.hadoop.io.Text不能轉換到org.apache.hadoop.io.IntWritable
後堆棧跟蹤,並指定該行拋出異常。 – talex
請添加堆棧跟蹤 – Sergii
int v = val.get();此行錯誤 –