function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandy singhSandy singh 

Error com/salesforce/api/String.equals

Hi All,

 

I am getting stranger error once I used equals method,

 

Code:

String selectedProgramName = 'abc';

for(Integer i=0;i<sample.size();i++) {

 if(sample[i].trim().equals(selectedProgramName)) {

 blnAddr = true;

 break;

}}

Error Message:

java.lang.AssertionError: apex.bytecodeinterpreter.InterpreterRuntimeException: Unable to resolve method reference: com/salesforce/api/String.equals(java/lang/String, java/lang/String) 

 

 

So can any one let me know region for this.

 

Thanks in advance,

Sandy

 

 

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

Damien_, that produces a different error:

 

13:37:13.027 (27494000)|EXCEPTION_THROWN|[4]|System.NullPointerException: Attempt to de-reference a null object
13:37:13.027 (27598000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Good guess, though.

 

 

Sandy, what is the datatype of sample? I'm guessing List, but I'd like to know for sure.

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code in system debug

String selectedProgramName = 'abc';

list<String >sample =new list<string>{'a','b','abc','xyz'};

boolean blnAddr =false;

for(Integer i=0;i<sample.size();i++) {

 

 if(sample[i].trim().equals(selectedProgramName)) {

 

 blnAddr = true;

 

 break;

 

}}

system.debug(blnAddr );

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Damien_Damien_

Is there any chance that sample[i] == null?  I would make sure it's not null first if you are using it like a normal array.

 

if(sample[i] != null && sample[i].trim().equals(selectedProgramName)) {

 

 

craigmhcraigmh

Damien_, that produces a different error:

 

13:37:13.027 (27494000)|EXCEPTION_THROWN|[4]|System.NullPointerException: Attempt to de-reference a null object
13:37:13.027 (27598000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Good guess, though.

 

 

Sandy, what is the datatype of sample? I'm guessing List, but I'd like to know for sure.

This was selected as the best answer
Damien_Damien_

If it produces that error... my best guess is that at that point sample itself is null.

craigmhcraigmh

Wouldn't it fail when testing for the size()?

Damien_Damien_

It would.  I guess its just hard to tell what's going on since we don't really see what sample is, but it could be erroring right when we are checking to see if the value is null before doing the functions on it.

craigmhcraigmh

Yeah, we need the preceding code for the sample variable. Until then, we just have to sit on our hands.

Sandy singhSandy singh

datatype of sample is list<string> and same code was working fine, but since few days its showing that errors.

If i used "==" oparator in place of equals method its work fine..

craigmhcraigmh

Odd, I wonder if that's an issue with they way they implemented the equals() method. Maybe it can't handle certain characters in your data.

 

There are a couple of interesting comments for the equals() method, but nothing that would explain this.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm