I receive the following error message:
Static method cannot be referenced from a non static context: System.Pattern System.Pattern.compile(String)
Here is my code:
private static Pattern pattern = Pattern.compile(String str);
public static List<String> getRecord(String record) {
List<String> patternRecord = new List<String>();
if(record == null || record.equals('')) {
return patternRecord;
}
Matcher recordMatcher = pattern.matcher(record);
while(recordMatcher.find()) {
String entireRecord = recordMatcher.group();
if(entireRecord != null && !entireRecord.equals('')) {
List<String> splitRecord = entireRecord.split('[,]');
for(String rec :splitRecord){
patternRecord.add(rec);
}
}
}
return patternRecord;
}
Please advise how to avoid such error?
Pattern.compile()
takes an argument that you omit here. That should produce a different error; getting the "wrong" error sometimes indicates there are other syntax issues.