Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects attributes accessing from a hashtable

 
Alex Garci
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two java classes: LecturaEscrituraObjetos and Venta. The first one is where are the methods to write and read objects from a file and it has the hashtable named th where the objects Venta are saved. The second one is the object that I want to write and read from a file.

There are no errors. The problem is that I don't know the way to access the methods of the object Venta from the hashtable. I tried it using toString(), Values() and Elements() methods but I only see something like Venta@1d009b4. I also tried use the Enumeration interface but I don't know how to copy the elements from the hashtable to the Enumeration.

Here is the code:





How can I acess to the Venta attributes?

Thanks.
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a Venta object. Seems you already have the Venta objects in the below array.
 
Michael Krimgen
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Very simple, you put the object into the hash table:



That you do already correctly. Now you can use the key to retrieve your object:



 
Alex Garci
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying Michael. But I tried it what you just typed and I displayed the following:

Venta@17ce4e7

I don't know why. The result would be 1, because is what I typed.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see problems with your Venta class. You have lots of fields, but you do not initialise them in your constructor. You have a Scanner object, which you never use, so you might as well delete it.
You ought to provide a constructor which initialises the Venta object and getXXX methods which allow access to its fields. You should find some similar examples here. All the fields should have private access, so access can only be through the getXXX methods.
As for the output, Venta@17ce4e7, start reading here.

why are you using Hashtable, which is legacy code? Why are you using floats?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic