2012-07-19 59 views
0

我通過Cygwin使用Hadoop運行Mapreduce作業。我得到以下NumberFormatException錯誤...任何想法如何我可以解決這個嘗試&捕獲外,因爲我認爲嘗試&趕上繞過錯誤,但不讓我得到我期望的結果。NumberFormatException錯誤

錯誤:

12/07/19 17:10:31 INFO mapred.JobClient: Task Id : attempt_201207190234_0010_m_000000_2, Status : FAILED 
java.lang.NumberFormatException: For input string: "MAX" 
     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) 
     at java.lang.Integer.parseInt(Integer.java:449) 
     at java.lang.Integer.parseInt(Integer.java:499) 
     at Node.<init>(Node.java:48) 
     at GraphJob$SearchMapper.map(GraphJob.java:18) 

這是我的映射和減少..

public class GraphJob { 

public static class SearchMapper extends Mapper<Object, Text, Text, Text>{ 
    public void map(Object key, Text value, Context context) 
        throws IOException, InterruptedException{ 
     try{ 
     Node inNode = new Node(value.toString()); 
     if(inNode.getColor() == Node.Color.GRAY) { 
      for(String neighbor : inNode.getEdges()) { 
       Node adjacentNode = new Node(); 

       adjacentNode.setId(neighbor); 
       int distance = inNode.getDistance() + 1; 
       adjacentNode.setDistance(distance); 
       if (distance < 2){ 
        adjacentNode.setColor(Node.Color.GRAY); 
       } 
       else{ 
        adjacentNode.setColor(Node.Color.BLACK); 
       } 
       adjacentNode.setParent(inNode.getId()); 
       context.write(new Text(adjacentNode.getId()), adjacentNode.getNodeInfo()); 
      } 

      inNode.setColor(Node.Color.BLACK); 
     } 

     context.write(new Text(inNode.getId()), inNode.getNodeInfo()); 
     }catch(Exception e){ 

     } 
    } 
} 

public static class SearchReducer extends Reducer<Text, Text, Text, Text> { 
    public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { 

     Node outNode = new Node(); 
     outNode.setId(key.toString()); 

     for (Text value : values) { 
      Node inNode = new Node(key.toString() + "\t" + value.toString()); 

      if(inNode.getEdges().size() >0) { 
       outNode.setEdges(inNode.getEdges()); 
      } 
      if (inNode.getDistance() < outNode.getDistance()) { 
       outNode.setDistance(inNode.getDistance()); 

       outNode.setParent(inNode.getParent()); 
      } 
      if (inNode.getColor().ordinal() > outNode.getColor().ordinal()) { 
       outNode.setColor(inNode.getColor()); 
      } 
     } 
     context.write(key, new Text(outNode.getNodeInfo())); 

    } 

} 

public static void main(String[] args) throws Exception { 

    Configuration conf = new Configuration(); 
    String[] otherargs = new GenericOptionsParser(conf, args).getRemainingArgs(); 
    Job job = new Job(conf, "GraphJob"); 
    job.setJarByClass(GraphJob.class); 
    job.setMapperClass(SearchMapper.class); 
    job.setReducerClass(SearchReducer.class); 
    job.setOutputKeyClass(Text.class); 
    job.setOutputValueClass(Text.class); 
    FileInputFormat.addInputPath(job, new Path(otherargs[0])); 
    FileOutputFormat.setOutputPath(job, new Path(otherargs[1])); 
    System.out.println("start the job"); 
    System.exit(job.waitForCompletion(true) ? 0 : 1); 
    } 


} 

這裏是我的文本文件的樣本..

1 2,7|0|GRAY|NULL 
2 3,6,8|MAX|WHITE|NULL 
3 2,4,5,6,8|MAX|WHITE|NULL 
4 3,5,9|MAX|WHITE|NULL 
5 3,4,8|MAX|WHITE|NULL 
6 2,3|MAX|WHITE|NULL 
7 1,8|MAX|WHITE|NULL 
8 2,3,5,7,9|MAX|WHITE|NULL 
9 4,8|MAX|WHITE|NULL 

輸出文件應該是

1 2,7|0|BLACK|NULL 
2 3,6,8|1|GRAY|1 
7 1,8|GRAY|1 
3 2,4,5,6,8|MAX|WHITE|NULL 
4 3,5,9|MAX|WHITE|NULL 
5 3,4,8|MAX|WHITE|NULL 
6 2,3|MAX|WHITE|NULL 
8 2,3,5,7,9|MAX|WHITE|NULL 
9 4,8|MAX|WHITE|NULL 

但與嘗試&抓...停止錯誤..我只得到..

1 2,7,|0|BLACK|NULL 
2 |1|GRAY|1 
7 |1|GRAY|1 
+0

我假設.getDistance返回一個int? – 2012-07-19 21:37:14

+0

是的,它確實返回一個int ...我有一個節點類與該 – 2012-07-19 21:40:03

+0

我添加了我的輸出文件應該是什麼,而我得到的,而是當我壓制錯誤,所以這就是爲什麼我認爲錯誤需要修復。 – 2012-07-19 21:44:35

回答

0

您可以在輸入文件中將MAX更改爲Integer.MAX_VALUE嗎?

1 2,7|0|GRAY|NULL 
2 3,6,8|Integer.MAX_VALUE|WHITE|NULL 
3 2,4,5,6,8|Integer.MAX_VALUE|WHITE|NULL 
4 3,5,9|Integer.MAX_VALUE|WHITE|NULL 
5 3,4,8|Integer.MAX_VALUE|WHITE|NULL 
6 2,3|Integer.MAX_VALUE|WHITE|NULL 
7 1,8|Integer.MAX_VALUE|WHITE|NULL 
8 2,3,5,7,9|Integer.MAX_VALUE|WHITE|NULL 
9 4,8|Integer.MAX_VALUE|WHITE|NULL 

您的輸出文件應反映新值。

+0

我最終做了相反的事情,並將Node類更改爲MAX,這是他們沒有匹配的問題,這與您所說的是相同的。 – 2012-07-26 00:24:13

0
java.lang.NumberFormatException: For input string: "MAX" 

您正試圖轉換字符串在代碼int值。在調用作業之前,確保你設置的值是int。

+0

那麼MAX也在輸出文件..所以我不知道如何解決這個問題。 – 2012-07-19 21:40:42