• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Storing data in an arraylist

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am currently working on an assignment and trying to get data from all fields and combo boxes stored in an arraylist after clicking a button.

Below is the code for adding data the the array list which is causing many an error code like symbol cannot be found.



sellerDayOB, sellerMonthOB, sellerYearOB, dayOfSale, monthOfSale, yearOfSale, endDayOfSale, endMonthOfSale, endYearOfSale, numOfBedrooms, numOfGarages, numOfToilets and propertyType are all comboboxes containing integers, the rest are textfields.


I also have a class named Sale which is shown below.



Is anyone able to help me out here with what I have done wrong? It would be greatly appreciated.

Thanks
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am going to check from the start;

For example here:




you need to be accurate:

 
Thomas Molloy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read that as of a Java SE version 7 you can leave the type parameters out of the right side diamond brackets. Is that not true?
 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Molloy wrote:I read that as of a Java SE version 7 you can leave the type parameters out of the right side diamond brackets. Is that not true?


Correct, starting with Java 7, use can you the diamond operator <> and avoid specifying the type parameters when instantiating.
 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Molloy wrote:Is anyone able to help me out here with what I have done wrong? It would be greatly appreciated.


There are multiple issues with your code.

When instantiating and initializing a new Sale object, decide if you are initialize the instance fields  in the constructor, or using setter methods - in your code, you are trying to do both.  Since you have so many fields to initialize, it would probbly be better to use setter methods.  To do this, you would need to have a no-arguments constructor.

Your Sale constructor specifies argument types like String, double, int, but when calling the contructor - it looks like you are passing references to Swing components.

You are naming the instance of your new Sale object saleList - this is the same name you gave to your list of Sale objects.  Also, you are trying to use the setters, you should be using the name of the instance, not the class - for example:


There are many setters which take numeric values, but you are passing-in strings.  For example:
something like this
rather than

 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and Welcome to CodeRanch!  
 
Thomas Molloy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ron, thank you for the reply. I made the changes you suggested but am still getting cannot find symbol errors, as well as a new error "constructor Sale in class Sale cannot be applied to given types".

 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the updated code and include the exact error messages that you are seeing (copy-and-paste if you can).
 
Thomas Molloy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Error messages:

constructor Sale in class Sale cannot be applied to given types;
Sale sale = new Sale();
           ^
required: String,String,double,int,int,int,String,int,int,int,int,int,int,int,int,int,int,double,String,double
found: no arguments
reason: actual and formal argument lists differ in length

error: cannot find symbol
sale.setPropertyArea(Double.parseDouble(propertyArea.getText()));

error: cannot find symbol
sale.setSalesCommission(addSalesCommission.getText());

error: cannot find symbol
sale.setSellerDOBDay(Integer.parseInt(sellerDayOB.getSelectedItem.toString()));

error: cannot find symbol
sale.setSellerDOBMonth(Integer.parseInt(sellerMonthOB.getSelectedItem.toString()));

error: cannot find symbol
sale.setSellerDOBYear(Integer.parseInt(sellerYearOB.getSelectedItem.toString()));

error: cannot find symbol
sale.setDayOfSaleOffer(Integer.parseInt(dayOfSale.getSelectedItem.toString()));

error: cannot find symbol
sale.setMonthOfSaleOffer(Integer.parseInt(monthOfSale.getSelectedItem.toString()));

error: cannot find symbol
sale.setYearOfSaleOffer(Integer.parseInt(yearOfSale.getSelectedItem.toString()));

error: cannot find symbol
sale.setSaleEndDay(Integer.parseInt(endDayOfSale.getSelectedItem.toString()));

error: cannot find symbol
sale.setSaleEndMonth(Integer.parseInt(endMonthOfSale.getSelectedItem.toString()));

error: cannot find symbol
sale.setSaleEndYear(Integer.parseInt(endYearOfSale.getSelectedItem.toString()));

error: cannot find symbol
sale.setNumOfBedrooms(Integer.parseInt(numOfBedrooms.getSelectedItem.toString()));

error: cannot find symbol
sale.setNumOfGarages(Integer.parseInt(numOfGarages.getSelectedItem.toString()));

error: cannot find symbol
sale.setNumOfToilets(Integer.parseInt(numOfToilets.getSelectedItem.toString()));




 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:...Since you have so many fields to initialize, it would probbly be better to use setter methods.  To do this, you would need to have a no-arguments constructor.


Did you add a no-arg constructor to the Sale class?
 
Thomas Molloy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my sale class now.

 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well .. it seems like the error message is saying that arguments required for the constructor and the arguments being passed to the constructor do not match.

If your code is correct, then maybe your IDE still has a copy of the previously compiled version of the Sale class.  Try building cleaning and building your application/project again.
 
Thomas Molloy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I created a clean build of the MainWindow class, and now have got rid of the constructor error, but the cannot find symbol error remains.
 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the error messages.
 
Thomas Molloy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MainWindow.java:300: error: cannot find symbol
sale.setSalesCommission(addSalesCommission.getText());
   ^
 symbol:   method setSalesCommission(String)
 location: variable sale of type Sale

MainWindow.java:302: error: cannot find symbol
sale.setSellerDOBDay(Integer.parseInt(sellerDayOB.getSelectedItem.toString()));
                                                ^
 symbol:   variable getSelectedItem
 location: variable sellerDayOB of type JComboBox<Integer>

MainWindow.java:303: error: cannot find symbol
sale.setSellerDOBMonth(Integer.parseInt(sellerMonthOB.getSelectedItem.toString()));
                                                    ^
 symbol:   variable getSelectedItem
 location: variable sellerMonthOB of type JComboBox<Integer>

MainWindow.java:304: error: cannot find symbol
sale.setSellerDOBYear(Integer.parseInt(sellerYearOB.getSelectedItem.toString()));
                                                  ^
 symbol:   variable getSelectedItem
 location: variable sellerYearOB of type JComboBox<Integer>

MainWindow.java:305: error: cannot find symbol
sale.setDayOfSaleOffer(Integer.parseInt(dayOfSale.getSelectedItem.toString()));
                                                ^
 symbol:   variable getSelectedItem
 location: variable dayOfSale of type JComboBox<Integer>

MainWindow.java:306: error: cannot find symbol
sale.setMonthOfSaleOffer(Integer.parseInt(monthOfSale.getSelectedItem.toString()));
                                                    ^
 symbol:   variable getSelectedItem
 location: variable monthOfSale of type JComboBox<Integer>

MainWindow.java:307: error: cannot find symbol
sale.setYearOfSaleOffer(Integer.parseInt(yearOfSale.getSelectedItem.toString()));
                                                  ^
 symbol:   variable getSelectedItem
 location: variable yearOfSale of type JComboBox<Integer>
MainWindow.java:308: error: cannot find symbol
sale.setSaleEndDay(Integer.parseInt(endDayOfSale.getSelectedItem.toString()));
                                               ^
 symbol:   variable getSelectedItem
 location: variable endDayOfSale of type JComboBox<Integer>

MainWindow.java:309: error: cannot find symbol
sale.setSaleEndMonth(Integer.parseInt(endMonthOfSale.getSelectedItem.toString()));
                                                   ^
 symbol:   variable getSelectedItem
 location: variable endMonthOfSale of type JComboBox<Integer>

MainWindow.java:310: error: cannot find symbol
sale.setSaleEndYear(Integer.parseInt(endYearOfSale.getSelectedItem.toString()));
                                                 ^
 symbol:   variable getSelectedItem
 location: variable endYearOfSale of type JComboBox<Integer>

MainWindow.java:311: error: cannot find symbol
sale.setNumOfBedrooms(Integer.parseInt(numOfBedrooms.getSelectedItem.toString()));
                                                   ^
 symbol:   variable getSelectedItem
 location: variable numOfBedrooms of type JComboBox<Integer>

MainWindow.java:312: error: cannot find symbol
sale.setNumOfGarages(Integer.parseInt(numOfGarages.getSelectedItem.toString()));
                                                 ^
 symbol:   variable getSelectedItem
 location: variable numOfGarages of type JComboBox<Integer>

MainWindow.java:313: error: cannot find symbol
sale.setNumOfToilets(Integer.parseInt(numOfToilets.getSelectedItem.toString()));
                                                 ^
 symbol:   variable getSelectedItem
 location: variable numOfToilets of type JComboBox<Integer>

MainWindow.java:314: error: cannot find symbol
sale.setPropertyType(propertyType.getSelectedItem.toString());
                                ^
 symbol:   variable getSelectedItem
 location: variable propertyType of type JComboBox<String>
14 errors
 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Molloy wrote:


Your Sale class doesn't have a method named setSalesCommission.  Do you mean setSalesCommissionPerc?


Thomas Molloy wrote:


JComboBox doesn't have an accessible field named getSelectedItem - you should be using the method getSelectedItem():
    sale.setSellerDOBDay(Integer.parseInt(sellerDayOB.getSelectedItem().toString()));


This is the same kind of problem for the other errors.
 
Thomas Molloy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OMG, no errors. You, sir, are a life saver! Thank you!
 
I don't always make ads but when I do they're tiny
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic