简体   繁体   English

我在编译源代码时遇到错误,它抛出下面给出的错误

[英]I am facing a error when I compile the source code, It is throwing an error that is given below

java java的

import myPack.*;
public class HelloWorld{

    public static void main(String args[])
        {
            int a=Integer.parseInt(args[0]);
            Factorial f= new Factorial();
            int d = f.fact(a);
            System.out.println("Factorial of " +a+ " is : " +d);
        }
}

Factorial.java Factorial.java

package myPack;

public class Factorial
{
        public int fact(int b)
    {
        int c=1;
        for(int i=b;i>0;i--)
        {
        c=c*i;
        }
        return c;
    }

}

E:\Packages>javac HelloWorld.java
HelloWorld.java:7: error: cannot access Factorial
                        Factorial f= new Factorial();
                        ^
  bad source file: .\Factorial.java
    file does not contain class Factorial
    Please remove or make sure it appears in the correct subdirectory of the sou
rcepath.
1 error

Put the file Factorial.java inside a folder called myPack . 将文件Factorial.java放入名为myPack的文件夹中。

Then launch javac using : javac HelloWorld.java 然后使用以下javac HelloWorld.java启动javac: javac HelloWorld.java

In java, the file structure has to follow packages. 在Java中,文件结构必须遵循包。 See this tutorial for more information. 有关更多信息,请参见本教程

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM