Results 1 to 4 of 4
Thread: items not being set
- 08-30-2012, 10:32 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 1
- Rep Power
- 0
items not being set
hey guys i have class Item
and class TransactionJava Code:public class Item extends ArrayList<String> { private int count; private String name; Item() { //name=""; count=0; } public int getcount() { return this.count; } public void setcount(int x) { this.count=x; } Item(String name) { this.name=name; } }
In my main class i have created an object of Transaction and trying to add items to it as given belowJava Code:import java.sql.ResultSet; import java.util.ArrayList; public class Transaction extends ArrayList<Item> { public Item getUniqueItem() { ResultSet rs; Database d=new Database(); Item unique=new Item(); String query="Select distinct(item_id) from item_transaction"; rs=d.sendQuery(query); try{ while(rs.next()) { unique.add(rs.getString(1)); } }catch(Exception e){} return unique; } public int countItems(Item item) { ResultSet rs; Database d=new Database(); String query=""; int count=0; for(String i:item) { System.out.print(i); query="SELECT count(*) FROM `item_transaction` where item_id="+i; rs=d.sendQuery(query); try{ while(rs.next()) { //System.out.print(rs.getString(1)); count=Integer.parseInt(rs.getString(1)); //System.out.print(count+"\t"); } }catch(Exception e){} } return count; } }
But wen i go to print the contents of Ci am getting nothing. Please help me in solving this issueJava Code:Transaction Ci=new Transaction(); for(String name:I) //here I is of type item { //System.out.print(name+"\t"); Ci.add(new Item(name)); }
Thanks
- 08-31-2012, 12:01 AM #2
Re: items not being set
Please make and post a small complete program that compiles, executes and shows the problem. Also post the output from the code so we know what to expect.
Short bits of code don't show all the different ways the code can go wrong.If you don't understand my response, don't ignore it, ask a question.
- 08-31-2012, 09:30 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: items not being set
Why on earth are you extending ArrayList?
I would say your model is wrong just based on that.
Once you'e sorted that out then we can look at this again if there's still a problem.
But when you do you need to show us how all these bits fit togther, including how you are printing out Ci, and what you expected to see vs what you do see.Please do not ask for code as refusal often offends.
- 08-31-2012, 10:16 AM #4
Re: items not being set
Cross posted
http://forum.codecall.net/topic/7157...-to-add-items/
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Unable to add Items to a JComboBox when those items are read from a file
By jiffi in forum AWT / SwingReplies: 8Last Post: 12-10-2011, 04:54 PM -
ListView Sub Items
By rolledback in forum AndroidReplies: 2Last Post: 09-21-2011, 09:21 PM -
Dividing 3 items, please help.
By Quizzle23 in forum New To JavaReplies: 18Last Post: 02-24-2011, 06:42 AM -
jlist items
By bullstreetboy in forum New To JavaReplies: 6Last Post: 04-12-2009, 05:30 PM -
different sort of items
By jrleonard in forum SWT / JFaceReplies: 0Last Post: 12-23-2008, 02:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks