-2

I'm supposed to instantiate an object by passing a double array containing values and invoke some methods and the results should come out on the console. My code:

public class Client {

    public static void main(String[] args) {
        RainLog log = new RainLog(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0);
        double[] inRangeValues = log.getInRange(0,0);
        for(int i=0; i<inRangeValues.length; i++)
        System.out.println(inRangeValues[i]);
  }
}

after running this appears on the console:

Exception in thread "main" java.lang.NullPointerException
at comp125.RainLog.getInRange(RainLog.java:73)
at comp125.Client.main(Client.java:7)

I click on:

at comp125.RainLog.getInRange(RainLog.java:73)

it directs me to my loop:

for(int i=0; i<data.length; i++)

which passed the JUnit test which I am not sure why. I am new to java and programming so not really sure where the problem is at.

curtisk
  • 19,950
  • 4
  • 55
  • 71
  • 1
    Does `getInRange(0,0)` actually get anything? – kgh Jul 23 '15 at 11:58
  • nope. i just copied that but even if i change the values the same thing comes out on the console – Bartholomew Tan Jul 23 '15 at 12:00
  • 2
    The exception has occurred in `getInRange()` method. More specifically on `line 73 in RainLog class`. You need to put that code. – Codebender Jul 23 '15 at 12:00
  • 2
    The problem is on line 73 of RainLog.java (that's what `(RainLog.java:73)` means in the exception stack trace). See this SO question and answer for more info on what a NullPointerException is: http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it/218510#218510 – Anthony Grist Jul 23 '15 at 12:01
  • 1
    @JishnuPrathap The NPE is being thrown by that method, so they won't be getting anything. – Anthony Grist Jul 23 '15 at 12:01
  • @AnthonyGrist you are right , the NPE is thrown in RainLog.java :73 – Jishnu Prathap Jul 23 '15 at 12:04

1 Answers1

4

data is null at line 73 of RainLog.java.

There must be somethiing wrong with your JUnit test as well if it passed without detecting this bug.

user207421
  • 305,947
  • 44
  • 307
  • 483