Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

incompatible types: String cannot be converted into int

What this type of error mean?

If you can post your code we can point out what is triggering the error and give an explanation as to why it throws the error.

2 Answers

Gavin Ralston
Gavin Ralston
28,770 Points

It likely means you're trying to assign a String value to a variable that is declared as another Type.

Like so:

public class Employee {

    String name;

}

Employee employee1 = "Bob";

Or maybe something like:

int guess = //some method or statement that collects input from the user at the console here....

...but then you never cast it to an integer, so the input came back as a String, even though you meant to store an integer or something.

So I'd check the call stack, find out what the line was that you're having trouble with, and just look at what that line might be trying to do, versus what you really want it to do.

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

Without seeing your code, did you do something like this with your integer & string?

int i = Integer.parseInt(myString);