-4

I am getting error "java.lang.nullpointerexception" in the code

 public int getProcessedData(final byte[] data, final int offset)
  {
    int size = bits.getBufferSize();
   System.arraycopy(bits.getBuffer(), 0, data, offset, size);
    bits.init();
    return size;
  }
Anika
  • 17
  • 1
  • 4
  • 3
    either *bits* or *data* is null. – TheLostMind Jul 31 '14 at 05:57
  • TheLostMind is correct - and we can't know which is null unless you send us more code or a better stack trace. – kviiri Jul 31 '14 at 05:57
  • http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – Deepanshu J bedi Jul 31 '14 at 05:58
  • public int getProcessedData(final byte[] data, final int offset) { int size = bits.getBuffeSize(); System.arraycopy(bits.getBuffer(),0, data, offset, size); bits.init(); return size; } public int getProcessedDataByteSize() { return bits.getBufferSize(); } getting null pointer exception in line no.4 – Anika Jul 31 '14 at 06:09

1 Answers1

0

Assign the values for bits/data

Null pointer exception appears when you declare a variable but did not create an 
object. If you attempt to dereference num BEFORE creating the object you get a 
NullPointerException.

Keep debugging the code, then you can easily find where the exception occurs.

flotothemoon
  • 1,882
  • 2
  • 20
  • 37
Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57
  • public int getProcessedData(final byte[] data, final int offset) { int size = bits.getBuffeSize(); System.arraycopy(bits.getBuffer(),0, data, offset, size); bits.init(); return size; } public int getProcessedDataByteSize() { return bits.getBufferSize(); } getting null pointer exception in line no.4 – – Anika Jul 31 '14 at 06:20
  • getting null pointer exception in: System.arraycopy(bits.getBuffer(),0, data, offset, size); – Anika Jul 31 '14 at 06:23