Results 1 to 4 of 4
  1. #1
    nyfer is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default items not being set

    hey guys i have class Item

    Java 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;
         }
        
      
       
    }
    and class Transaction


    Java 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;
       }
       
        
       
       
    }
    In my main class i have created an object of Transaction and trying to add items to it as given below

    Java 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));
          }
    But wen i go to print the contents of Ci am getting nothing. Please help me in solving this issue
    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default 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.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default 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.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: items not being set

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 8
    Last Post: 12-10-2011, 04:54 PM
  2. ListView Sub Items
    By rolledback in forum Android
    Replies: 2
    Last Post: 09-21-2011, 09:21 PM
  3. Dividing 3 items, please help.
    By Quizzle23 in forum New To Java
    Replies: 18
    Last Post: 02-24-2011, 06:42 AM
  4. jlist items
    By bullstreetboy in forum New To Java
    Replies: 6
    Last Post: 04-12-2009, 05:30 PM
  5. different sort of items
    By jrleonard in forum SWT / JFace
    Replies: 0
    Last Post: 12-23-2008, 02:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •