0

I'm facing a Java error but I don't understand why, thats why I post a question here.

I got this error:

No such property: split for class: java.lang.String

With this code:

String cellContent = "[COLUMN columnRef, test]"
cellContent = cellContent.substring(1, cellContent.length() - 1)
String[] splitContent = cellContent.split(', ')
String rowToUse = splitContent[1]
String splitColumn = splitContent[0].split[' ']
String column = splitColumn[1]

Expected result

rowToUse = "test"
column = "columnRef"

The error occurred on this line : String splitColumn = splitContent[0].split[' ']

Someone has any idea? Thanks a lot!

2
  • 1
    That's not Java (no semicolons). Is it Groovy? Commented Jun 14, 2019 at 15:25
  • Yep but I use Java functions thats why I mentionned Java tag Commented Jun 14, 2019 at 15:26

2 Answers 2

5
splitContent[0].split[' ']

Use roundy brackets for split: it's a method invocation:

splitContent[0].split(' ')
Sign up to request clarification or add additional context in comments.

Comments

2

You need to use round brackets instead of square brackets in:

String splitColumn = splitContent[0].split(" ")

since you are trying to call a function and not reference an array index.

1 Comment

This is groovy, single quotes are fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.