Why do i encounter 'error: incompatible types' in java?

Example:

String str = 12345;

This error indicates you're trying to assign a value of one type to a variable of another incompatible type.

Solution:

Make sure the types on the left and right side of the assignment are compatible.


String str = "12345";

Beginner's Guide to Java