java - 在java中找不到错误

标签 java compiler-errors

关闭。这个问题不符合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/

相关文章:

java - 如果在 Java 中的局部变量范围之外使用,列表将显示为 null

java - 在Java中从JTable创建pdf文件

java - 如何准确测量 drawTextOnPath() 在 Canvas 上绘制的文本的像素大小

C++ 源代码错误——计算距离和总和的差异

compiler-construction - D编程: openssl rsa forward reference compiler error

c++ - 这是什么编译错误?

xcode - 图像.xcassets : error: ERROR: Each TDDistiller instance can be distilled only one time

java - 如何在具有不同类型值的 Map 中使用泛型

gcc - 为什么 GCC 4.3 出现 "Redefinition of typedef"错误而不是 GCC 4.6?

java - Eclipse 插件问题 : icons/images show fine locally but not from jar/update site.