Reputation: 23
Im getting this problem in my constructor i want to be able to take supplierName from the supplier class and add it to product.
public class Product {
private long id;
private long barcode;
private String description;
private String zone;
private int quantity;
Supplier supplierName;
public Product(){
}
public Product(long id, long barcode, String description, String zone,
int quantity, Supplier supplierName) {
super();
this.id = id;
this.barcode = barcode;
this.description = description;
this.zone = zone;
this.quantity = quantity;
this.supplierName = supplierName;
}
But the problem lies when i get to my product service class
public class ProductService {
private Map<Long, Product> products = DatabaseClass.getProducts();
public ProductService(){
products.put(1L,new Product(1,1,"Lighter","Gift",5000,"Supplier1"));
products.put(2L,new Product(2,2,"Lighter","Gift",3500,"supplier2"));
}
its giving me an error for the supplier1
& supplier2
.
Any help would be appriciated.
Upvotes: 0
Views: 73
Reputation: 44398
If you edit the formatting of your code, you can clearly see you try to parse the Strings "Supplier1"
and "supplier2"
to the constructor, which accepts the Supplier
as the object type.
If you have a defined class Supplier
, change the constructor call to:
products.put(2L,new Product(2,2, "Lighter","Gift",3500,new Supplier(...)));
Or if the supplier is supposed to be the String, change its declaration and the constructor.
private String supplier;
public Product(long id, long barcode, String description, String zone, int quantity, String supplier) { .... }
The conclusion in all the cases is: Please, DO formatting! :)
Upvotes: 1
Reputation: 4507
You are giving String in "Supplier1"
and Supplier2
, while constructor expects Object "Supplier"
Upvotes: 0