user3473227
user3473227

Reputation:

Change Return type error in Eclipse

I keep getting the following error in Eclipse:

"The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String)"

Here is the code:

public class names {

private String nameOne;
  public void setName(String name){
     nameOne=name;
  }
  public String getName(){
     return nameOne;
  }
  public void saying(){
     System.out.printf("Your name is %s", getName());
  }
}

Please help explain what I should do. I tried to remove "String", but that was silly. I'm somewhat new so a detailed explaination would not be overkill (though the short, simple, correct responses are always the best).

Upvotes: 0

Views: 497

Answers (1)

Dileep
Dileep

Reputation: 5440

The issue was due to the wrong Compiler compliance level

To solve it you must change your Compiler compliance level in eclipse by doing this

1) Right-click on your project

2) Click Properties

3) Click the "Java Compiler" option on the left menu

4) Under JDK compliance section on the right, change it to "1.5" or above

Java Compiler compliance level

The Compiler compliance level indicates that which JDK level of source must be used for compilation.

For eg :

If you are using some components which is defined in earlier versions of Java JDK and was removed from the later versions. Then you must use the older version of JDK to compile your code. For this the eclipse provide the use of multiple compliance level, ie; even if you are using the latest version of JDK. You can tell the compiler to compile with an older version.

The JDK 1.5 implemented the printf() method in the java.io.PrintStream class that offers the same formatting capabilities as the printf function in stdio library in C. Look on Other Developer-Friendly Enhancements for details.

Upvotes: 2

Related Questions