我非常确定数组正确定义时的.class错误

时间:2019-03-14 03:36:33

标签: java arrays

测试器类:

public class StoreTester
{
public static void main(String [] args)
{
    Store DarthV = new Store("Darth Vader Costume", 2, 1956, 29.99);
    Store HanS = new Store("Han Solo Costume", 6, 2856, 15.99);
    Store gLightsaber = new Store("Green Light Saber", 7, 8234, 5.99);
    Store bLightsaber = new Store("Blue Light Saber", 10, 8235, 5.99);
    Store rLightsaber = new Store("Red Light Saber", 4, 8233, 5.99);
    Store StormTroop = new Store("Storm Trooper Costume", 2, 1955, 25.99);
    Store DarthM = new Store("Darth Mual Costume", 4, 1957, 28.99);
    Store R2D2 = new Store("R2D2 Plush", 6, 1238, 12.99);
    Store C3PO = new Store("C3PO Plush", 4, 1240, 16.99);
    Store KyloR = new Store("Kylo Ren Costume", 2, 1960,  
    Store[] items = new Store[]{ DarthV, HanS, gLightsaber, bLightsaber, rLightsaber, StormTroop, DarthM, R2D2, C3PO, KyloR};
}
}

商店类别:

public class Store
{
//instance variables
private int quantity; 
private int productNum;
private double price;
private String name;

//Constructor for objects of class Store
public Store(String name, int quantity, int productNum, double price){
    this.name = name;
    this.quantity = quantity;
    this.productNum = productNum;
    this.price = price;
}

public String getName(){
    return name;
}

public int getQuantity(){
    return quantity;
}

public int getProductNum(){
    return productNum;
}

public double getPrice(){
    return price;
}

public String toString(){
    String string = String.format("%-30s %4d %-20d %3.2f", name, quantity, productNum, price);
    return string;
}
}

在用这样的对象初始化数组之前,这从未发生过。由于某种原因,即使我非常确定已正确初始化了数组,也遇到了“'.class'预期”错误。有人可以帮助我找出为什么以前从未收到过此错误的原因吗?该错误发生在测试器类的最后一行代码上。

0 个答案:

没有答案