Hello,

  I'm stuck with this for two days now ...I found a previous post discussing 
this, but not with arrays.

 I know how to write Writable class with primitive type elements but this time 
I'm using an ARRAY of primitive type element, here it is in a simplified 
version for easy readability :

public class twoIntegersArrayWritable implements Writable {

        private int vectorSize;
        private twoIntegers[] vector ;
    
        /* CONSTRUCTORS */  ===================================================

        twoIntegersArrayWritable () {}

        twoIntegersArrayWritable (int size, twoIntegers[] vec) {
                this.vectorSize = size;         
                this.vector = vec;
        }

        /* WRITE FUNCTION */  
===================================================       

        public void write(DataOutput out) {     

                out.writeInt(this.vectorSize);
                for(int i=0;i<this.vectorSize;i++){
                        out.writeInt( vector[i]. getFirstIntger());
                        out.writeInt( vector[i]. getSecondIneger());
                }
        }

        /* READ FUNCTION */  
===================================================        
       
        public void readFields(DataInput in) throws IOException {
                
                this.vectorSize = in.readInt();         
                this.CreateNewVector (this.vectorSize);
                for(int i=0;i< this.vectorSize;i++){                            
                        this.vector[i].setFirstInteger(in.readInt());
                        this.vector[i].setSecondInteger(in.readInt());
                }
        }
}

The errors I get:
java.lang.NullPointerException
        at twoIntegersArrayWritable.readFields(twoIntegersArrayWritable.java:46)
        at 
org.apache.hadoop.io.SequenceFile$Reader.getCurrentValue(SequenceFile.java:1751)
        at org.apache.hadoop.io.SequenceFile$Reader.next(SequenceFile.java:1879)
        at SequenceFileReader_Integers.main(SequenceFileReader_Integers.java:49)

Or it would work fine but array size is always 0. So it won't read the integer 
fields.

It would be helpful if someone already has an example of using array in their 
Writable class. I appreciate any thought. 

Maha

Reply via email to