Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从一个类调用另一个类中的方法?_Java_Compiler Errors - Fatal编程技术网

Java 如何从一个类调用另一个类中的方法?

Java 如何从一个类调用另一个类中的方法?,java,compiler-errors,Java,Compiler Errors,我正在尝试调用另一个类中的statemotOfPhilosopy 有两类: 一等设置站点: package setupsite; public class SetUpSite { public static void main(String[] args) { statementOfPhilosophy(); } public static void statementOfPhilosophy() { System.out.printl

我正在尝试调用另一个类中的
statemotOfPhilosopy

有两类:

一等
设置站点

package setupsite;

public class SetUpSite {
    public static void main(String[] args) {
        statementOfPhilosophy();
    }

    public static void statementOfPhilosophy() {
        System.out.println("Even Handlers Incoroporated is");
        System.out.println("dedicated to making your event");
        System.out.println("a most memorable one.");
    }
}
第二类
调用方法

package callingmethods;

public class CallingMethods {
    public static void main(String[] args) {
        System.out.println("Calling method from another class:");
        SetUpSite.statementOfPhilosophy(); //Error here at the SetUpSite
    }
}

您必须导入
setupsite
包。 您的代码如下所示:

package callingmethods;
import setupsite.SetUpSite;

public class CallingMethods {


    public static void main(String[] args) {
        System.out.println("Calling method from another class:");
            SetUpSite.statementOfPhilosophy(); //Error here at the SetUpSite
    }

}

您必须
在此处导入setupsite
包:

import setupsite;

然后再试。

您忘记添加导入语句添加此行:
导入setupsite.setupsite




怎么了?是否导入了
SetUpSite
?是否导入了SetUpSite类:
import SetUpSite.SetUpSite
您收到了什么错误消息?
    package setupsite;
    public class SetUpSite {        
        public static void main(String[] args) {
            statementOfPhilosophy();
        }
        public static void statementOfPhilosophy()
        {
            System.out.println("Even Handlers Incoroporated is");
            System.out.println("dedicated to making your event");
            System.out.println("a most memorable one.");
        }         
    }
package callingmethods;
import setupsite.SetUpSite

public class CallingMethods {
    public static void main(String[] args) {
        System.out.println("Calling method from another class:");
            SetUpSite.statementOfPhilosophy(); 
    }
}