views:

931

answers:

4

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

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

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

encoded = encode_monoalphabetic_engine(string);
A: 

Perhaps you could post a more complete code snippet?

It looks like your method argument string isn't a java.lang.String?

toolkit
+1  A: 

Make sure that the other method is returning also a "java.lang.String", not a user defined object "string".

ZiG
A: 

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

kd304
A: 

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

indyK1ng