Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toString() Error, Cannot resolve method toString()

I am trying to convert the int id I get back from a model called Part in a search functionality I am building to a string so I can simplify the search.

Here is the if statement I have used so far:

if(part.getId().toString().indexOf(searchText) > -1) {
return true;}

When I try to convert this id to a string, I am shown an error that says Cannot resolve method toString()

Here is the get method in the Part model I am using:

public int getId() { return id; }

Not sure what I am doing wrong here?

I am using JavaFX 11

like image 248
James Johnson Avatar asked Jul 27 '26 11:07

James Johnson


1 Answers

You can't call a method on primitive types like double, int, float in Java.

Use String.valueOf(part.getId()) instead.

like image 188
Akshat Tiwari Avatar answered Jul 29 '26 02:07

Akshat Tiwari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!