Java - 无法调用编译错误方法 [英] Java - Compile Error Method Can't be Called

查看:100
本文介绍了Java - 无法调用编译错误方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to compile my code with a Testing Tool, however, when that testing tool calls my method, I receive this error:

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

"method getCourseDetails in class Course cannot be applied to given types;

必需:java.lang.String,int,java.lang.String,boolean,java.lang.String.java.lang。字符串,双

required: java.lang.String,int,java.lang.String,boolean,java.lang.String.java.lang.String,double

找到:无参数

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

reason: actual and formal argument lists differ in length.

您在此处使用的运算符不能用于您使用它的值类型。您要么使用错误的类型,要么使用错误的运算符。

The operator that you use here cannot be used for the type of value that you are using it for. You are either using the wrong type here, or the wrong operator."

这是我的方法:

   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 + "\"");    


推荐答案

你的问题是你没有通过合适的参数进入方法,因此它吐出错误。

Your problem is that you are not passing in the appropriate parameters into the method, hence it spits out that error.

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

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

For this code, you need to pass in all of those variables in that same order (1st string, 2nd int, etc.). You can't just all getCourseDetails() with nothing inside it and expect something to happen, because all the information you're trying to process in that method never actually goes inside of it.

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

So, for example, when you call this method, it may look like this

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);

这篇关于Java - 无法调用编译错误方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆