Incompatible type Java error

I am writing Java code using the NetBeans IDE. I keep getting a couple of "Incompatible Type" errors. I declare a variable as a String and then assign a value to it from a method that also returns a string. The error says that the expected type was "String", but instead found "...", where "..." is the name of the method I'm calling.

For example, this is the line that gives me the error:

incompatible types
found: encode_monoalphabetic_engine
required: java.lang.String

encoded = encode_monoalphabetic_engine (string);
0


source to share


4 answers


Make sure the other method also returns "java.lang.String" and not a "user-defined" object.



+1


source


Perhaps you could post a more complete piece of code?



Sounds like your method argument is string

n't java.lang.String

?

0


source


I think the compiler doesn't recognize encode_monoalphabetic_engine as a method / function. Maybe you have some name conflicts or bad scope.

0


source


I agree with kd304, it looks like the program doesn't recognize the method call as such. I am assuming "string" is your variable name for the String object. Just make sure you are calling the method correctly and that the method returns a String data type.

0


source







All Articles