在Hadoop中实现自定义Writable?(Implementation of custom Writable in Hadoop?)
我在Hadoop中定义了一个自定义的Writable类,但Hadoop在运行我的程序时给出了以下错误消息。
java.lang.RuntimeException: java.lang.NullPointerException at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115) at org.apache.hadoop.io.SortedMapWritable.readFields(SortedMapWritable.java:180) at EquivalenceClsAggValue.readFields(EquivalenceClsAggValue.java:82) at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:67) at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:40) at org.apache.hadoop.mapred.Task$ValuesIterator.readNextValue(Task.java:1282) at org.apache.hadoop.mapred.Task$ValuesIterator.next(Task.java:1222) at org.apache.hadoop.mapred.Task$CombineValuesIterator.next(Task.java:1301) at Mondrian$Combine.reduce(Mondrian.java:119) at Mondrian$Combine.reduce(Mondrian.java:1) at org.apache.hadoop.mapred.Task$OldCombinerRunner.combine(Task.java:1442) at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:1436) at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1298) at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:437) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372) at org.apache.hadoop.mapred.Child$4.run(Child.java:255) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1136) at org.apache.hadoop.mapred.Child.main(Child.java:249)
引起:java.util.concurrent.ConcurrentHashMap.hash的java.lang.NullPointerException(ConcurrentHashMap.java:332)....
EquivalenceClsAggValue是我定义的Writable类的名称,这是我的类:
public class EquivalenceClsAggValue implements WritableComparable<EquivalenceClsAggValue>{ public ArrayList<SortedMapWritable> aggValues; public EquivalenceClsAggValue(){ aggValues = new ArrayList<SortedMapWritable>(); } @Override public void readFields(DataInput arg0) throws IOException { int size = arg0.readInt(); for (int i=0;i<size;i++){ SortedMapWritable tmp = new SortedMapWritable(); tmp.readFields(arg0); aggValues.add(tmp); } } @Override public void write(DataOutput arg0) throws IOException { //write the size first arg0.write(aggValues.size()); //write each element for (SortedMapWritable s:aggValues){ s.write(arg0); } }
我想知道问题的根源是什么。
I have defined a custom Writable class in Hadoop, but Hadoop gives me the following error message when running my program.
java.lang.RuntimeException: java.lang.NullPointerException at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115) at org.apache.hadoop.io.SortedMapWritable.readFields(SortedMapWritable.java:180) at EquivalenceClsAggValue.readFields(EquivalenceClsAggValue.java:82) at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:67) at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:40) at org.apache.hadoop.mapred.Task$ValuesIterator.readNextValue(Task.java:1282) at org.apache.hadoop.mapred.Task$ValuesIterator.next(Task.java:1222) at org.apache.hadoop.mapred.Task$CombineValuesIterator.next(Task.java:1301) at Mondrian$Combine.reduce(Mondrian.java:119) at Mondrian$Combine.reduce(Mondrian.java:1) at org.apache.hadoop.mapred.Task$OldCombinerRunner.combine(Task.java:1442) at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:1436) at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1298) at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:437) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372) at org.apache.hadoop.mapred.Child$4.run(Child.java:255) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1136) at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:332)....
EquivalenceClsAggValue is the name of the Writable class I've defined and this is my class:
public class EquivalenceClsAggValue implements WritableComparable<EquivalenceClsAggValue>{ public ArrayList<SortedMapWritable> aggValues; public EquivalenceClsAggValue(){ aggValues = new ArrayList<SortedMapWritable>(); } @Override public void readFields(DataInput arg0) throws IOException { int size = arg0.readInt(); for (int i=0;i<size;i++){ SortedMapWritable tmp = new SortedMapWritable(); tmp.readFields(arg0); aggValues.add(tmp); } } @Override public void write(DataOutput arg0) throws IOException { //write the size first arg0.write(aggValues.size()); //write each element for (SortedMapWritable s:aggValues){ s.write(arg0); } }
I wonder to know what is the source of the problem.
原文:https://stackoverflow.com/questions/14249128
最满意答案
我对
.fancybox()
并不是很了解,但是你可以试试这个想法。将您不希望在页面上显示的图像放在隐藏的容器中。 它们不会在页面上显示,但我想他们会在fancybox中。
HTML
<body> <div id='hiddenContainer' style='display:none;'></div> <a rel="example_group" href="./example/7_b.jpg"><img alt="" src="./example/7_s.jpg" /></a> <a rel="example_group" href="./example/9_b.jpg"><img alt="" src="./example/9_s.jpg" /></a> </body>
在jQuery中,将图像附加到该容器。
$(document).ready(function() { $("<a rel='example_group' href='./example/8_b.jpg'><img src='./example/8_s.jpg' /></a>") .appendTo("#hiddenContainer"); $("a[rel=example_group]").fancybox(); });
I don't really know much about
.fancybox()
, but here's an idea you might try.Place the images that you don't want displayed on the page in a container that is hidden. They won't be visible on the page, but I would imagine they would be in the fancybox.
HTML
<body> <div id='hiddenContainer' style='display:none;'></div> <a rel="example_group" href="./example/7_b.jpg"><img alt="" src="./example/7_s.jpg" /></a> <a rel="example_group" href="./example/9_b.jpg"><img alt="" src="./example/9_s.jpg" /></a> </body>
In jQuery, append the image to that container.
$(document).ready(function() { $("<a rel='example_group' href='./example/8_b.jpg'><img src='./example/8_s.jpg' /></a>") .appendTo("#hiddenContainer"); $("a[rel=example_group]").fancybox(); });
相关问答
更多-
您的问题在.innerHTML ,它会在每次迭代时中断DOM,这意味着先前添加的事件将被清除,并且您只将侦听器附加到最后一个元素。 您可以使用DOM API来创建和附加这些元素,一切都会正常工作:jsfiddle.net/HtxZb 但是,我建议使用事件委托。 没有jQuery,您可以像这样实现它: document.getElementById('list') .addEventListener('click', function(event){ var elem = event ...
-
尝试像这样:因为你的'li'是动态生成的( 为了进一步阅读 ) $("body").on('click','li',function(){ $(this).nextAll().css({"color":"red"});; }); Try like this : As your 'li' are generating dynamically ( For further reading ) $("body").on('click','li',function(){ $(this).nextAl ...
-
验证新创建的元素(Validating newly created elements)[2022-02-12]
为你创造了一个完整的小提琴; http://jsfiddle.net/7KLA6/ 更新根据请求添加代码 HTML