Error in passing Java parameter

Asked

Viewed 86 times

1

I’m starting to learn Java and I’m having a problem with a simple code I did. It is a program that reads a text input and then prints on the screen, but when trying to compile this error occurs here

Exception in thread "main" java.lang.Error: Unresolved Compilation problem:

The method printf(String, Object[]) in the type Printstream is not applicable for the Arguments (String, String)

At Beginning.GradeBookTest.main(Gradebooktest.java:30)

Gradebook class:

package Beginning;
//Declaração de classe com um método

public class GradeBook {
    
    public String courseName; //Nome do curso para esse GradeBook
    
    //Método para configurar o nome do curso
    public void setCourseName(String name){
        courseName = name;//Armazena o nome do curso
    }//Fim do método setCourseName
    
    //Método para recuperar o nome do curso
    public String getCourseName(){
        return courseName;
    }//Fim do método getCourseName
    
    //Exibe uma mensagem de boas-vindas para o usuário GradeBook
    
    public void displayMessage(){
        /*Chama getCourseName para obter o nome do
         * curso que essa GradeBook representa*/
        System.out.printf("Welcome to the GradeBook for\n%s!\n", getCourseName());
    }
} //Fim da classe GradeBook

Class of the main:

package Beginning;
import java.util.Scanner; //Importando a função Scanner
//Criando um objeto GradeBookTest e chamando seu método displayMessage
public class GradeBookTest {
    
    public static void main (String[] args){
        //Cria Scanner para obter entrada a partir da janela de comando
        Scanner input = new Scanner(System.in);
        
        //Cria um objeto GradeBook e o atribui a myGradeBook
        GradeBook myGradeBook = new GradeBook();
        
        //Exibe o valor inicial de courseName
        System.out.printf("Initial course name is: %s\n\n", myGradeBook.getCourseName());
        
        //Solicita e lê o nome do curso
        System.out.println("Please, enter the course name: ");
        String theName = input.nextLine();//Lê uma linha de texto
        myGradeBook.setCourseName(theName);//Configura o nome do curso
        System.out.println();//Gera saída de uma linha em branco
        /*Exibe mensagem de boas-vindas depois 
         * de especificar o nome do curso*/
        myGradeBook.displayMessage();
    }//Fim de main
} //Fim da classe GradeBookTest
  • The problem must be elsewhere, here "worked": https://ideone.com/nBO5JV

  • I also ran Netbeans 8.2 and it worked.

  • 1

    I solved it! It was a compiler problem. I was using 1.4 and switched to 1.6. To change just go to window -> preferences -> java -> Compiler.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.