gpt4 book ai didi

Java 拒绝检测任何类库

转载 作者:行者123 更新时间:2023-11-30 05:27:17 25 4
gpt4 key购买 nike

这感觉非常像另一个问题的重复,但我一直无法找到解决方案。在 Eclipse(Java) 和 JGrasp 中,无论我做什么,IDE 都拒绝编译我拥有的类库。

我已经尝试使用构建路径配置在 Eclipse 中手动添加库,在工作区中创建一个文件夹,将类文件复制到其中,然后将该文件夹添加到类路径中。

在 JGrasp 中,我读到只需将类文件与运行程序文件放在同一目录中就足够了。



public class PayrollLoop
{
public static void main(String[] args)
{
// Prepare to receive output
Scanner scan = new Scanner(System.in);

// initialize variables
int numberEmployees = 0;
double totalGrossPay = 0;
double averagePay = 0;

Payroll employee = new Payroll();
String repeat = "yes";

// Loop to ask for repeated entry of employees.
// New String method: stringObject.equals(anotherStringObject).
// This method returns a boolean value of True or False.

while ( repeat.equals("yes") )
{
// prompt and scan for employee name
System.out.print("Enter the name: ");
employee.setName( scan.next() );

// prompt and scan for ID number
System.out.print("Enter the id number: ");
employee.setIdNumber( scan.nextInt() );

// prompt and scan for pay rate
System.out.print("Enter the pay rate: ");
employee.setPayRate( scan.nextDouble() );

// prompt and scan for hours worked
System.out.print("Enter the number of hours worked: ");
employee.setHoursWorked(scan.nextDouble());


// what should you do to the numberEmployees variable here?
numberEmployees ++;

// what should you do to the totalGrossPay variable here?



// use the getter methods to print all the employee values
System.out.println("Name " + employee.getName());
System.out.println("Id number " + employee.getIdNumber());
System.out.println("Pay Rate " + employee.getPayRate());
System.out.println("Hours Worked " + employee.getHoursWorked());
System.out.println("Gross Pay " + employee.grossPay());
System.out.println();

// Ask user if entering another and scan for response
System.out.println();



} // end of the while loop



// calculate average pay
averagePay = totalGrossPay / numberEmployees;



// print average pay
System.out.println("The average pay is: " + averagePay);




} // end of main method
}

jGASP 错误:

 ----jGRASP exec: javac -g PayrollLoop.java
---- at: Oct 8, 2019, 1:15:39 PM

----jGRASP wedge: pid for wedge is 2648.
----jGRASP wedge2: pid for wedge2 is 784.
----jGRASP wedge2: CLASSPATH is ";.;;;C:\Program Files (x86)\jGRASP\extensions\classes".
----jGRASP wedge2: working directory is [H:\APCS\2019-2020 AP Computer Science\Unit 2\payrolltest] platform id is 2.
----jGRASP wedge2: actual command sent ["C:\Program Files\jdk-10.0.2\bin\javac.exe" -g PayrollLoop.java].
----jGRASP wedge2: pid for process is 5304.

PayrollLoop.java:35: error: ';' expected
System.out.println("Enter the pay rate: ")
^
1 error

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

类文件已编译。

最佳答案

在jGRASP中,打开“设置”>“详细消息”,然后编译的输出也会显示类路径。您的类路径可能有些奇怪。

确保 Employee.class 命名正确(正确的大小写,没有隐藏的附加扩展名)。

如果 Employee 位于包中,则需要将该包结构复制为目录结构,因此,如果它位于包“company”中,则需要在包含“Main”(或其他位置)的目录中名为“company”的目录在类路径上),并且 Employee.class 将位于该目录中。

如果您确实有此库的 .jar 版本,则可以使用“设置”>“PATH/CLASSPATH”>“工作空间”(或“项目...”,如果您使用的是项目)将其添加到jGRASP 中的类路径。

关于Java 拒绝检测任何类库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58273184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com