我是hadoop編程的新手,並嘗試減少邊連接時出現錯誤錯誤:java.lang.NumberFormatException:對於輸入字符串:「100」。 我已檢查輸入文件是否正常。錯誤:java.lang.NumberFormatException:對於輸入字符串:「100」
我減速器代號爲'
public void reduce (IntWritable key , Iterable<Text> value , Context context) throws IOException , InterruptedException{
// value : TRAN\t product name \t Amt and CUST \t custometr name
String data = new String();
int amount=0;
String name =null;
StringBuilder s = new StringBuilder();
for (Text val : value){
String[] line = val.toString().split("\t");
if (line[0].equals(new String("TRANS").trim())){
//data += line[1]+"\t";
s.append(line[1]+"");
amount+=Integer.parseInt(line[2]);
}
else if(line[0].equals(new String("CUST").trim())){
name = line[1];
}
data= s.toString()+ Integer.toString(amount);
context.write(new Text(name), new Text(data));
和我的兩個映射是:
package reduceSideJoin.reducejoin;
public class transMapper extends Mapper<LongWritable ,Text , IntWritable , Text > {
public void map(LongWritable key , Text value , Context context) throws IOException , InterruptedException{
String[] line = value.toString().split(",");
String data = "TRANS"+ "\t" + line[1]+"\t " + line[3];
context.write(new IntWritable (Integer.parseInt(line[0])), new Text(data));
}
}
和
package reduceSideJoin.reducejoin;
public class userMapper extends Mapper<LongWritable, Text, IntWritable, Text> {
public void map (LongWritable key, Text value , Context context) throws IOException , InterruptedException{
String [] line = value.toString().split(",");
String data = "CUST"+"\t"+line[1];
context.write(new IntWritable (Integer.parseInt(line[0])), new Text(data));
}
}
和我的文件
交易數據
0001,crax,2,300
0002,munch,1,10
0003,lays,1,20
0004,ship,1,200
0005,barOne,3,400
0002,crax,2,300
0001,kurkure,3,100
0003,milk,1,20
0004,butter,2,300
0005,meat,1,1220
0002,color,1,230
0003,dailrymilk,1,20
和客戶數據是
0001,Sunil Kumar , Mumbai,India
0002,Vikas mandal, Haryana, India
0003,Karan, JFK,France
0004,manish,banglore,India
0005,devesh,meerut,India
和我得到錯誤16/05/30 0點23分00秒INFO mapreduce.Job:地圖100%減少0% 16/05/30 00: 23:04 INFO mapreduce.Job:任務標識:attempt_1464547777880_0001_r_000000_0,狀態:FAILED 錯誤:java.lang.NumberFormatException:對於輸入字符串: 「100」 在java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
有人可以幫我解決這個問題
感謝
有似乎是在'」 100" '一個虛假的空間。 – Tunaki
在輸入字符串上使用trim()函數刪除空格示例amount + = Integer.parseInt(line [2] .trim()); – AGdev
我已將我的Reducer代碼更改爲'amount + = Integer.parseInt(line [2] .trim());'但現在它顯示空指針異常 –