-1

Error thrown"java.lang.NullPointerException: Cannot invoke method readLine() on null object error at Line 1" when below groovy script is run on SOAP UI Version 5.1.3

nextLine = context.fileReader.readLine()
if(nextLine != null){
String[] propData = nextLine.split(",") 
curTC = testRunner.testCase
albciff
  • 18,112
  • 4
  • 64
  • 89
Pramod
  • 1
  • 1
  • 2
  • 1
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – SiKing Oct 01 '15 at 13:37

1 Answers1

1

The error message is clear, context.fileReader is null because there is no property fileReader inside context, this is why you get the NPE when you invoke readLine() on it.

To use context.fileReader, first you've to set something in the property, for example in your case:

context.fileReader = new FileReader("/myTempFile.txt")
def nextLine = context.fileReader.readLine()
if(nextLine != null){
String[] propData = nextLine.split(",") 
curTC = testRunner.testCase

This example has non sense at all, it's only illustrative; normally context in SOAPUI is used to pass different objects from one testStep to another inside a TestCase execution, or from one TestCase to another inside a TestSuite etc...

For example you have a TestCase and want to pass a property through different testSteps, in one TestStep you set the property as:

context.fileReader = new FileReader("/myTempFile.txt")

And then in another TestStep you get it back to use it as:

def nextLine = context.fileReader.readLine()

Hope this helps,

albciff
  • 18,112
  • 4
  • 64
  • 89