2011-04-11 127 views
-1

可能重复:
I get an error when I try to compile my java code below: not sure for it to compile can anyone help? I don't understand the int in the error message.我不明白的INT错误消息

当我尝试下面编译我的Java代码,我仍然收到此错误信息:

//作者:Donna Gary //日期:2011年4月10日 //等级:IT/215第五周库存计划1

import java.text.NumberFormat; import java.util.Locale; import java.util.Scanner;

类电视{

private String itemNumber; 
private String productName; 
private double units; 
private double unitPrice; 
private double unitsTotal; 

//constructor 
public Television (String itemNumber, String productName, double units, double unitprice, double unitsTotal) { 
    setItemNumber(itemNumber); 
    setProductName(productName); 
    setUnits(units); 
    setUnitPrice(unitPrice); 
    unitsTotal = units ++; 

} 

//accessor methods for class variables 
public String getItemNumber() { 
    return itemNumber; 
} 

public void setItemNumber (String itemNumber) { 
    this.itemNumber = itemNumber; 
} 

public String getProductName() { 
    return productName; 
} 

public void setProductName (String productName) { 
    this.productName = productName; 
} 

public double getUnits() { 
    return units; 
} 

public void setUnits (double units) { 
    this.units = units; 
} 

public double getUnitPrice() { 
    return unitPrice; 
} 

public void setUnitPrice (double unitPrice) { 
    this.unitPrice = units * unitPrice; 
} 

public double getUnitsTotal() { 
    return unitsTotal; 
} 

public void setUnitsTotal (double unitsTotal) { 
    this.unitsTotal = units ++; 
} 

} 公共类InventoryPart1 {

public static void main (String args[]) { 


    int units; 

    double unitPrice; 

    double unitsTotal; 
    unitsTotal = units ++; 

    double unitsPrice; 
    unitsPrice = units * unitPrice; 

    double unitsTotalPrice; 
    unitsTotalPrice = unitsTotal * unitPrice; 

    double totalInventory; 
    totalInventory = unitsTotal * unitsTotalPrice; 


    NumberFormat nf = NumberFormat. getCurrencyInstance(Locale.US); 

    //create an instance of the Television class 
    Television samsung = new Television ("SAMSUNG 46 6400 Series”,” Samsung Smart TV”, “UN46D6400UF"); 

    //use the methods from class Television to output the inventory details. 
    System.out.println("Item Number: " + samsung.getItemNumber()); 

    System.out.println("Product Name: " + samsung.getProductName()); 

    System.out.print("Number of Units: "); 
    System.out.println(nf.format(units)); 

    System.out.print("Unit Price: "); 
    System.out.println(nf.format(unitPrice)); 

    System.out.print("Units Total: "); 
    System.out.println(nf.format(unitsTotal)); 

    System.out.print("Units Total Price: "); 
    System.out.println(nf.format(unitsTotalPrice)); 

    System.out.print("Total Inventory: "); 
    System.out.println(nf.format(totalInventory)); 
} 

}

我不明白错误消息的int。 。

C:\\Documents and Settings\AdminUser\My Documents\InventoryPart1.java:96: 
cannot find symbol symbol : constructor Television(java.lang.String) 
location: class Television 
Television samsung = new Television("SAMSUNG 46 6400 Series","Samsung SmartTV", "UN46D6400UF"); 
        ^1 error Tool completed with exit code 1 
+0

你能发布你的代码吗?没有它,很难知道发生了什么。 – juanchopanza 2011-04-11 17:20:00

+0

代码?或者添加一个与Television(String name)相匹配的构造函数。 – 2011-04-11 17:20:05

+0

什么是int?你是在谈论.java之后的96,还是退出代码1? – 2011-04-11 17:20:15

回答

1

你试图呼吁Televsion构造有一个说法,一个String,并没有这样的构造存在。问题出现在InventoryPart1.java的第96行。

3

这只是一个错误代码,可能表示编译器返回错误。

真正的问题是您的编译器不认为constructor Television(java.lang.String)存在。您可能需要修复对构造函数的调用,修复构造函数或添加与此调用相匹配的新构造函数。

1

您的返回码1表示异常终止。在这种情况下,这是因为它无法编译你的代码。

原因是因为您试图拨打的电视类没有找到。这可能有两种可能性:

  1. 编译器可以找到类,但不能找到构造函数。你正在调用一个不存在的构造函数。为电视添加一个新的构造函数或者调用一个现有的构造函数。
  2. 该类本身不在类路径中。您可以将代码/ jar移动到您的类路径已指向的某个位置,或重新定义您的类路径。
0

您是不是又发布了这个问题?电视有一个构造函数 Television(字符串a,字符串b,字符串c),并且只给出1个字符串作为输入。你需要打破SAMSUNG 46 6400系列,三星智能电视,UN46D6400UF 3个不同的字符串不是1

编辑

啊问题是关于INT。 96应该是发现错误的那一行。

0

你在用什么IDE?尝试使用IntelliJ。它有一个免费的社区版本。当你遇到这样的问题时,它会给你提供很好的建议。它也会在你编码的时候编译,所以你很快就会收到你的错误。

+0

谢谢你的信息将尝试这一点。 – Donna 2011-04-11 17:59:01