2016-08-30 68 views
1

我努力做到以下几点:
写入空值到拼花文件,映射器

String x=null; 
    Group group = factory.newGroup() 
      .append("x", x); 
context.write(null,group) 


使用以下方案:

String writeSchema = "message example {\n" + 
    "optional binary x;\n" + 
    "}";<br> 

但我在append行得到的NullPointerException 。也许我在计划中缺少一些东西?

回答

2

这里的String对象本身是null。在写入文件系统时,它会尝试获取导致NullPointerExeception的对象的值。

String x =null; 
System.out.println(x.toString()); // Will cause a NullPointerExeception 

同样,任何对该对象的函数调用都会导致相同的结果。

尝试使用String x ="null"代替