当前位置: 首页 > 面试题库 >

Java-无法调用编译错误方法

越俊艾
2023-03-14
问题内容

我必须使用测试工具编译我的代码,但是,当该测试工具调用我的方法时,我收到此错误:

“课程Course中的getCourseDetails方法不能应用于给定类型;

必需:java.lang.String,int,java.lang.String,boolean,java.lang.String.java.lang.String,double

找到:没有参数

原因:实际参数列表和形式参数列表的长度不同。

您在此处使用的运算符不能用于您用于其的值的类型。您在这里使用了错误的类型或错误的运算符。”

这是我的方法:

   public static void getCourseDetails(String department, int number, String name, boolean isFull, 
       String SCHOOL_NAME, String motto, double price){
   if (department.length() != (0) && number != 0 && name.length() != (0) && price != 0) {
        System.out.print(department + " ");
    } else if (department.length() == (0)){
        System.out.print ("Sorry, there is an error with the course department.");
        return;
    }
   if (number == 0) {
        System.out.print("Sorry, there is an error with the course number.");
        return;
    } else if (number != 0 && department.length() != (0) && name.length() != (0) && price != 0){
        System.out.print(number + " ");
    }
   if (name.length() != (0) && number!= 0 && department.length() != (0) && price != 0) {
        System.out.println(name + ".");
    } else if (name.length() == (0)) {
        System.out.print("Sorry, there is an error with the course name.");
        return;
    }
   if (price  == 0){
        System.out.print("Sorry, there is an error with the course price.");
        return;
    } 
    //System.out.println(department + " " + number + " is " + name);
   if (isFull == true){
        System.out.println("The course is currently full.");
    } else if (isFull == false){
        System.out.println("The course is currently not full.");
    }
   System.out.println("The course is currently run at " + SCHOOL_NAME + 
   " where their motto is " + "\"" + motto + "\"");

问题答案:

您的问题是您没有将适当的参数传递给方法,因此它会吐出该错误。

public static void getCourseDetails(String department, int number, String name, boolean isFull, 
   String SCHOOL_NAME, String motto, double price){

对于此代码,您需要以相同的顺序传递所有这些变量(第一个字符串,第二个int等)。您不能只在其中没有任何内容的所有getCourseDetails()并期望发生某些事情,因为您试图在该方法中处理的所有信息实际上都不会进入其中。

因此,例如,当您调用此方法时,它可能看起来像这样

String department = "Math";
int number = 101;
String name = "Williams";
boolean isFull = false;
String SCHOOL_NAME = "Pinkerton High"
String motto = "We Never Sleep"
double price = 100.0;
//note that the variable names do not have to be the same here
//as they are in the method
getCourseDetails(department, number, name, isFull, SCHOOL_NAME, motto, price);


 类似资料:
  • 问题似乎出在代码上。..它指向/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/,而它需要查看jar所在的/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/lib/。谢谢你的回答…

  • 问题内容: 我想用Java中的XSLT转换XML。为此,我使用了包装。但是,我得到了例外。这是我正在使用的代码: 请注意,我标记了引发异常的行。 当我输入方法时,的值为: 问题答案: 该构造 从URL构造StreamSource。我认为您正在传递XSLT的内容。试试这个: 你还必须设置你的意愿写:

  • 问题内容: 我在使用webstorm打字稿编译器时遇到问题。我有以下课程 因此,键入“ super”,我会在智能感知中看到所有rootData公共方法。但是在设置super.insert()之后,出现以下错误: TS2340:仅可通过’super’关键字访问基类的公共和受保护的方法 在TS游乐场中尝试过,它正在工作(认为是简化版本)。 谢谢你的帮助。 编辑:检查编译的javascript后,超级方

  • 我当前正在获取和生成失败的错误。尝试卸载android Studio,卸载并重新安装java,但无效。谢谢你的建议。非常感谢。 失败:生成失败,出现异常。 > 出了什么问题:任务执行失败:app: greendao。 <区块报价> 在解析/xxx/android/app/src/main/java/com/eatsy/打印机/Printer.java时发现4个问题。第一个问题:Pb(324)无法解

  • 我正在与ATM案例研究一起工作,从Deitel java如何编程第9版。 案例研究在第13章,第546页(万一有人有这本书并想要查看),我确信我的代码是100%如书中所建议的那样。 我已经设置了所有的代码,但当我尝试运行程序时,它给了我以下信息: 当我试图从类路径使用terminal编译类时,它给出了以下错误: 这是正在进行的课程:直截了当地往前走,但我似乎找不到问题所在。有人帮忙吗?

  • 问题内容: 为什么在Java中,即使没有抛出异常,我们也可以捕获它,但是却不能捕获它的子类(“ unchecked” 及其子类除外)。示例代码: 有任何想法吗? 问题答案: 任何 代码都可以引发A。换句话说,编译器无法轻松预测可以抛出哪种代码。阿可通过捕获块。 __ 但是,这是一个检查的异常- 只有声明为抛出该异常的方法调用才可以这样做。编译器可以(合理地)确信除非有声明将其抛出的方法调用,否则它