java - Error: the method getId() is undefined for the type List<Product> -


i have method create list of objects of class

public list<product> initproducts(){     list<product> product = new arraylist<product>();          product prod = new product(product.getid(),product.getitemname(),product.getprice(),product.getcount());         product.add(prod);      return product; } 

my product class is:

public class product {  int itemcode; string itemname; double unitprice; int count;  /**  * initialise fields of item.  * @param name name of member of product.  * @param id number of member of product.  * @param price price of member of product.  */  public product(int id, string name, double price, int c) {     itemcode=id;     itemname=name;     unitprice=price;     count = c; }  public int getid() {    return this.itemcode; }  public string getitemname() {    return this.itemname; }  public double getprice() {    return this.unitprice; }  public int getcount() {    return this.count; }    /**  * print details members of product class text terminal.  */ public void print() {     system.out.println("id: " + itemcode);     system.out.println("name: " + itemname);     system.out.println("staff number: " +unitprice);     system.out.println("office: " + count);  } } 

i getting error method getid() undefined type list<product>, other methods. please me out error.

is statement correct??

product prod = new product(product.getid(),product.getitemname(), product.getprice(),   product.getcount()); product.add(prod); 

is statement correct??

product prod = new product(product.getid(),product.getitemname(), product.getprice(),   product.getcount()); product.add(prod); 

no incorrect. product not instance of class product,rather instance of list. list not have method called getid.

if want retrieve elements list , use create instance of can like:

product exisprod = product.get(0); product prod = new product(exisprod .getid(),exisprod .getitemname(), exisprod .getprice(),       exisprod .getcount()); 

but make sure have elements in list, otherwise u may run exception. product.add(prod);


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -