toString() Error, Cannot resolve method toString()

Viewed 367

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

1 Answers

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

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

Related