2016-06-12 40 views
1

編寫示例代碼以測試hadoop中的customdata。我收到以下錯誤:IntWritable.set(IntWritable)拋出錯誤

The method set(int) in the type IntWritable is not applicable for the arguments (IntWritable)

我已經檢查了set方法IntWritable.set(int value)。 如何將hadoop IntWritable轉換爲Int,然後返回IntWritable#set方法將轉換回IntWritable

public class customText implements Writable{ 

private Text depName; 

//default constr 
private IntWritable depId; 
customText(){ 
    this.depName = new Text(); 
    this.depId = new IntWritable(); 

} 

customText(Text depName , IntWritable depId){ 

    this.depName.set(depName); 
    this.depId.set(depId); 

我也試過this.depid=depId但它沒有奏效。

感謝

+2

['IntWritable.get()'](https://hadoop.apache.org/docs/r2.6.2/api/org/apache/hadoop/io/IntWritable.html#get())?真的,你應該在發佈問題之前總是查閱文檔。 – Seelenvirtuose

回答

2

它應該是:

customText(Text depName , IntWritable depId){ 
    this.depName.set(depName); 
    this.depId.set(depId.get()); 
} 

爲集的方法簽名是set(int value),所以你必須get()IntWritable整型。

+0

再次感謝@Binary Nerd的幫助 –