Java文件错误:无法找到或加载主类

时间:2017-01-17 07:25:05

标签: java

我在将程序加载到linux服务器时遇到了麻烦。我能够从我正在使用的IDE中复制粘贴我的代码并让服务器编译并运行代码,执行为空。我将行println更改为printf并且文件将无法编译并且每次都给出错误“无法找到或加载主类Program01”。包括当我粘贴刚刚工作的旧代码时,我正在尝试的一切都失败了。寻找关于我可以修复的其他意见。它从数字为“312032486”的输入文件中提取。只是想知道为什么它无法找到或加载主类。我相信其他一切都按预期工作。

感谢所有看过并打开任何设备的人,因为我是java的新手。

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package program01;

import java.util.Scanner;

/**
*
* @author Devin
*/
public class Program01 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    // Create variables for birth rate, death rate and immigration raet
    int birthRate = 1 / 7;
    int deathRate = 1 / 13;
    int immigrationRate = 1 / 45;

    // Variable creating the number of seconds per year
    int secondsPerYear = 60 * 60 * 24 * 365;

    // Variable to find births, deaths and immigrants added per year
    int birthsPerYear = birthRate * secondsPerYear;
    int deathsPerYear = deathRate * secondsPerYear;
    int immigrantsPerYear = immigrationRate * secondsPerYear;

    // Scanner method to GET population through input.data
    Scanner sc = new Scanner (System.in);
    System.out.printf("Enter population: ");
    int population = sc.nextInt();
    System.out.printf("Population is: " + population);

    // Math to create variables for population per X year
    double populationYear0 = population;
    double populationYear1 = populationYear0 + birthsPerYear - deathsPerYear + immigrantsPerYear;
    double populationYear2 = populationYear1 + birthsPerYear - deathsPerYear + immigrantsPerYear;
    double populationYear3 = populationYear2 + birthsPerYear - deathsPerYear + immigrantsPerYear;
    double populationYear4 = populationYear3 + birthsPerYear - deathsPerYear + immigrantsPerYear;
    double populationYear5 = populationYear4 + birthsPerYear - deathsPerYear + immigrantsPerYear;

    // Print out the variables data from code above
    System.out.println("Population Year 0: " + populationYear0);
    System.out.println("Population Year 1: " + populationYear1);
    System.out.println("Population Year 2: " + populationYear2);
    System.out.println("Population Year 3: " + populationYear3);
    System.out.println("Population Year 4: " + populationYear4);
    System.out.println("Population Year 5: " + populationYear5);

}

}

1 个答案:

答案 0 :(得分:0)

在评论中发表评论后,我确信删除/cs116 Program01.class 就足够了。如果您的类位于某个包中,则必须将该文件放在相应的目录中。

OP文件夹结构是:

$('button').on('click',function(){}

所以包声明无效。删除包声明将解决问题。