List of object

zolf
zolf used Ask the Experts™
on
Hello there,

can somebody help me to put the order into the Order object.i get error
Type mismatch: cannot convert from List<Order> to Order

@Override
	public void saveOrder(List<Order> order)
	{
		// TODO Auto-generated method stub
		System.out.println(" list Size  "+order.size());
		
		List<NameValuePair> params = new ArrayList<NameValuePair>(order.size());
		
		params.add(new BasicNameValuePair("action", "save_order"));
		
		for(int i=0;i<order.size();i++)
		{
			Order order2 = order;
			System.out.println(" inside FOR " +order2.getCustomerID() +"  "+order2.getProductID()+"  "+order2.getQty());
			
			params.add(new BasicNameValuePair("amount_"+i, Integer.toString(order2.getQty())));
			params.add(new BasicNameValuePair("prod_id_"+i, Integer.toString(order2.getQty())));
		}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
replace line # 13 with below,

Order order2 = order.get( i ) ;
for(Order order2 : order)		{
System.out.println(" inside FOR " +order2.getCustomerID() +"  "+order2.getProductID()+"  "+order2.getQty());
			
params.add(new BasicNameValuePair("amount_"+i, Integer.toString(order2.getQty())));
params.add(new BasicNameValuePair("prod_id_"+i, Integer.toString(order2.getQty())));
		} 

Open in new window

Top Expert 2016
Commented:
This is a case where using properly self-documenting code and the correct choice of variable names would have made such a fundamental error less likely to occur. The method prototype should have been not

public void saveOrder(List<Order> order)

Open in new window


but

public void saveOrder(List<Order> orders)

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial