简体   繁体   English

类型为nammi的方法epli(String [])不适用于arguments()

[英]The method epli(String[]) in the type nammi is not applicable for the arguments ()

Im new to java and im just trying to use this method 'epli' from another class but when i try to do it it says 我是java的新手,我只是试图从另一个类使用这个方法'epli',但当我尝试这样做时,它说
The method epli(String[]) in the type nammi is not applicable for the arguments ()

im using eclipse here is all the code: 我在这里使用eclipse是所有的代码:

import java.util.Scanner;
    public class nammi{
        public void epli(String args[]){
        System.out.println("Mér finnst nammi gott");
        }
    }

    public class siggi {
        public static void main(String args[]){
        System.out.println("Eg heiti ekki siggi");
            nammi nammi = new nammi();
            nammi.epli();
        }
    }

You defined epli as: 您将epli定义为:

public void epli(String args[])

So you need to provide an String array when you call it. 所以你需要在调用它时提供一个String数组。

If you change the signature of epli to 如果您将epli的签名更改为

public void epli()

you can call it the way you are doing it 你可以按照你的方式来调用它

Your method accepts a String[] data type but you are passing it nothing. 您的方法接受String []数据类型,但您没有传递任何内容。 You have to pass it a String[]. 你必须传递一个String []。

nammi.epli();

should become 应该成为

nammi.epli(new String[5]);

or some other String array. 或其他一些String数组。 You can also pass it a null if you want, but that's not what you should do in this case 如果需要,您也可以将它传递给null,但在这种情况下,这不是您应该做的

nammi.epli(null);

Change the signature of the epli() method to use varargs syntax: 更改epli()方法的签名以使用varargs语法:

public void epli(String... args){

Within the epli() method, args will actually still has a type of String[] . epli()方法中, args实际上仍然具有String[]类型。

Now your calling code will work, and you can pass parameters like this: 现在您的调用代码将起作用,您可以传递这样的参数:

nammi.epli(); // OK - args is an empty array (not a null)
nammi.epli("foo"); // args is array size 1
nammi.epli("foo", "bar"); // args is array size 2 etc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部分类型中的方法setText(String)不适用于参数 - method setText(String) in the type Part is not applicable for the arguments 类型“ x”的方法search()不适用于参数(字符串) - The method search() in the type “x” is not applicable for the arguments (String) 类型中的方法不适用于参数 - Method in the type is not applicable to the arguments 类型中的方法不适用于参数 - The method in the type is not applicable for the arguments 类型中的方法不适用于参数 - the method in type not applicable for the arguments 类型中的方法不适用于参数 - The method in the type is not applicable for the arguments JsonObject类型的方法add(String,JsonElement)不适用于参数(String,String) - The method add(String, JsonElement) in the type JsonObject is not applicable for the arguments (String, String) 类型中的方法不适用于参数(int) - The method in the type is not applicable for the arguments (int) double类型的方法parsedouble字符串不适用于double参数 - the method parsedouble string in the type double is not applicable for the arguments double PrintStream 类型中的 printf(String, Object[]) 方法不适用于参数 (...) - The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (...)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM