关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
7年前关闭。
Improve this question
我创建了两个类应用程序,类是 1. InVoice 2. InVoiceTest,我将 InVoice 类导入 InVoiceTest 这里是 InVoice 类
public class InVoice
{
private String name;
private String description;
private int quantity;
private double price;
public InVoice (String n, String d, int q, double p)
{
name=n;
description=d;
quantity=q;
price=p;
}
public void set (String n, String d, int q, double p)
{
name=n;
description=d;
quantity=q;
price=p;
}
public String getname()
{
return name;
}
public String getdescription()
{
return description;
}
public int getquantity()
{
return quantity;
}
public double getprice()
{
return price;
}
}
这是 InVoiceTest 类
import java.util.Scanner;
public class InVoiceTest
{
public static void main (String [] aa)
{
InVoice object=new InVoice();
Scanner obj=new Scanner (System.in);
System.out.print("Enter Item name: ");
String name=obj.nextLine();
System.out.print("\nEnter Item description: ");
String description=obj.nextLine();
System.out.print("\nEnter quantity: ");
int quantity=obj.nextInt();
System.out.print("\nEnter price: ");
double price=obj.nextDouble();
object.set(name,description, quantity, price);
}
}
这两个类都在同一个目录中,我正在通过命令提示符编译它们,并且一次又一次地显示此错误
InVoiceTest.class can not find symbol
symbol: constructor InVoice()
location: class InVoice
InVoice object=new InVoice();
最佳答案
如果您没有构造函数,Java 编译器将为您创建一个无参数构造函数。
只要您提供了一个有参数的构造函数,编译器就不会创建无参数构造函数。
因此,如果您向 InVoice 添加无参数构造函数(如下所示),它应该可以工作。
public InVoice() {
}
关于java - 在java中找不到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27053776/