Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:57:32+00:00 2026-06-10T15:57:32+00:00

This is my Item class: public class Item { private String id; private int

  • 0

This is my Item class:

public class Item {

 private String id;
 private int count;
 private String  name;

public int getcount() {
   return this.count;
}

public Item(String name) {
     this.name=name;
     this.id = "";

 }

public Item(String id, String name) {
   this.name=name;
   this.id=id;
 }

public Item(int count) {
    this.count=count;
}

public String getItemName() {
    return this.name;
}

public String getItemId() {
    return this.id;
}

public Item returnItems(ItemList itemset) {
    Item item=null;
    return item;
  }
}

This is my ItemList class which will contain a List of items:

public  class ItemList implements Iterable<Item>  {

  private List<Item> hold=new ArrayList<Item>();



  ItemList(Item item) {
    this.hold.add(item);
  }

  ItemList() {
    //throw new UnsupportedOperationException("Not yet implemented");
  }


  public List<Item> getItemSet() {
    return this.hold;
  }


  public void addItems(Item item) {
    this.hold.add(item);
  }


  @Override
  public Iterator<Item> iterator() {
    Iterator<Item> item = hold.iterator();
    return item;
  }
}

This is the Transaction class:

public class Transaction implements Iterable {

 private List<ItemList> trans=new ArrayList<ItemList>();

 public List<Item> getUniqueItems() {

    Database d = new Database();
    List<Item> unique = new ArrayList<Item>();

    String query="Select id,name from item";
    ResultSet rs = d.sendQuery(query);
    try {
        while(rs.next()) {
           // System.out.println(rs.getString(1)+"\t"+rs.getString(2));
            unique.add(new Item(rs.getString(1),rs.getString(2)));
        }
    }
    catch(Exception e){
        System.out.print(e.getMessage());
    }
    return unique;
}

public ItemList getUniqueItem() {
     ResultSet rs;
     Database d=new Database();
     ItemList unique=new ItemList();
      String query="Select id,name from item";
      rs=d.sendQuery(query);
        try{
        while(rs.next())
         {
           //System.out.println(rs.getString(1)+"\t"+rs.getString(2));
           Item item=new Item(rs.getString(1),rs.getString(2));
           unique.addItems(item);
    }

    } catch(Exception e) {
       System.out.print(e.getMessage());
    }

    return unique;
}


public void addTransaction(ItemList itemList) {
     this.trans.add(itemList);
}

public List<ItemList> getTransaction() {
     return this.trans;
}

@Override
public Iterator<ItemList> iterator() {
    Iterator<ItemList> itemList = trans.iterator();
    return itemList;
}

public int countItems(ItemList itemList) {
      ResultSet rs;
      Database d=new Database();
      String query="";
      int count=0;
      for(Item i:itemList)
     {
       System.out.println(i);
       String id=i.getItemId();
        System.out.print(id+"\t");
        query="SELECT count(*) FROM `item_transaction` where item_id="+id;
          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;
 }

 }

And this is my main class:

public class Ap {

public static void main(String args[])
{
   Transaction t=new Transaction();
    Transaction Ci=new Transaction();
   Transaction Li=new Transaction();

    List<Item> list = t.getUniqueItems();
    for(Item i:list)
    {
        ItemList itemList=new ItemList(i);
        Ci.addTransaction(itemList);
    }

}

After adding itemList to Transaction, I want to iterate over Ci and pass itemList to the countItems method in the Transaction class.

I tried:

for(ItemList list:Ci) {
    int x=t.countItems(list);
}

But am getting:

found  java.lang.Object
      Required ItemList

Or do I have to get the List<ItemList> from the Transaction class and then iterate?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:57:34+00:00Added an answer on June 10, 2026 at 3:57 pm

    You need to make

     class Transaction implements Iterable<ItemList>
    

    As it is you are saying that its Iterable of plain Objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi have one class like this import java.util.ArrayList; public class MobilePhone { private String
I'm using SharedPreferences to persists Object fields. Take this example: class Item { private
I have simple item model with name and quantity: public class Item extends CouchDbDocument{
I am using this Custom Adapter for my ListView: public class SideMenuAdapter extends BaseAdapter
I am receiving an error at this line return folder.SubFolders.Aggregate(count, (current, subfolder) => GetFilesCount(subfolder,
I have this item renderer MyRenderer.mxml <?xml version=1.0 encoding=utf-8?> <mx:HBox xmlns:mx=http://www.adobe.com/2006/mxml implements=mx.core.IDataRenderer > <mx:Script>
Why is this item not shown properly in my bibliography? @misc{ann, abstract = {ANN
I am getting json response like this {item_id:1,item_title:Item 1}{item_id:2,item_title:Item 2} how would I parse
So in the code below you'll notice the comment // This item is obfuscated
I have a View that renders something like this: Item 1 and Item 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.