• 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

reading a private method within a class

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure why my code does not seem to run the readIcons() private method in the Deck class...



I would like to know whether CardIcons and sequentialCardIcons are being loaded with images, and, to unit test that the images are in order.

Any idea whether which of a two-dimensional array or a one dimensional array is more efficient in terms of memory and why? Am I using an appropriate data structure for storing images?

Some of the images can be found here.



 
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jon,

I am not sure about the data structure needed for images, but i can help with the readIcons() method.
You cant call instance methods from your constructor,so if you really want to call the method, youu need to qualify it with the static modifier!!!...

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jishnu dasgupta wrote:You cant call instance methods from your constructor,so if you really want to call the method, youu need to qualify it with the static modifier!!!...



This is completely incorrect.

I expect the code at line 88 (in your post) is not being executed because an exception is being thrown before control reaches that point. And since at line 91 you specifically wrote code to ignore all exceptions, you won't find that out very easily. So don't do that (ignore exceptions, I mean).

Jon Camilleri wrote:Any idea whether which of a two-dimensional array or a one dimensional array is more efficient in terms of memory and why?



I don't have any idea. But that's the wrong question anyway. How big is this array? If it isn't going to take many megabytes it doesn't matter in the least whether it takes 10,000 bytes or 12,000 bytes. Use whichever is easier to write the code for.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is that line 86 is throwing an exception because you never initialise CardIcons. Follow Paul's advice and you'll be able to confirm that.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Incidentally: Deck extends Card? A deck is-not-a card, so that's poor design that's going to cause problems at some point.
 
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Pedantic mode]There's no such thing as a 2-D array. Only a 1-D array, of 1-D arrays[/pedantic mode]

Don't know whether an array or array of arrays is more efficient. I would think the difference is probably slight, and you ought not to worry about such considerations unless there are signs of slow performance.
You appear only to be calling that method from your constructor, and you have correctly labelled the method private. Any advice that you can't call instance methods from a constructor is mistaken. Does every overloaded constructor call that method? I presume you haven't commented out the call to the method, as you have in your 1-argument constructor.

You have got far too much code which you haven't tried. You ought to write about 5 lines, compile and run the code, and see what sort of errors you suffer. Then you will know the code is actually running.
Add some debugging code inside that method. Start like this:Add some code to print out the names of the files you are opening, so you can verify they are correct.
You have got an empty catch block: put something "real" in it, egThe break; instruction is obscuring any errors and exceptions, so you don't find out what is going wrong.
Never, never write == true or == false. Both are poor style and very error-prone.
You ought not to start identifiers with _ (except in package names).
 
jishnu dasgupta
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrrrrgh!!!........



Sorry Jon and thanks paul.....dont know how i made that stupid mistakes..........

.....Guess its time to go to sleep!!!.....
 
jishnu dasgupta
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Besides it was my 13th post..!!!...had to go wrong....
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jishnu dasgupta wrote:Hey Jon,

I am not sure about the data structure needed for images, but i can help with the readIcons() method.
You cant call instance methods from your constructor,so if you really want to call the method, youu need to qualify it with the static modifier!!!...



I can't make readIcons() static, because it would crash the program anyway:


Error

Cannot make a static reference to the non-static field sequentialCardIcons

at Deck.readIcons(Deck.java:63)
at Deck.<init>(Deck.java:18)
at Poker.main(Poker.java:6)


 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:[Pedantic mode]There's no such thing as a 2-D array. Only a 1-D array, of 1-D arrays[/pedantic mode]

Don't know whether an array or array of arrays is more efficient. I would think the difference is probably slight, and you ought not to worry about such considerations unless there are signs of slow performance.
You appear only to be calling that method from your constructor, and you have correctly labelled the method private. Any advice that you can't call instance methods from a constructor is mistaken. Does every overloaded constructor call that method? I presume you haven't commented out the call to the method, as you have in your 1-argument constructor.

You have got far too much code which you haven't tried. You ought to write about 5 lines, compile and run the code, and see what sort of errors you suffer. Then you will know the code is actually running.
Add some debugging code inside that method. Start like this:Add some code to print out the names of the files you are opening, so you can verify they are correct.
You have got an empty catch block: put something "real" in it, egThe break; instruction is obscuring any errors and exceptions, so you don't find out what is going wrong.
Never, never write == true or == false. Both are poor style and very error-prone.
You ought not to start identifiers with _ (except in package names).



Thanks.

I could not get ex.printStackTrace() to work somehow, when trying to add the following lines to my exception handling block:


However, enabling the exceptions to be displayed resulted that the image files cannot be read, and, I still could not figure out

1. Why it can't read the GIF files from the directories?
2. How can I specify relative sub-directories (i.e. look for /img/01.GIF.. img/02.GIF up to img/52.gif. Not all of the image files exist at the moment?


Output
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\01.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\02.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\03.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\04.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\05.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\06.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\07.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\08.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\09.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\10.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\11.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\12.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\13.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\14.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\15.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\16.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\17.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\18.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\19.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\20.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\21.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\22.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\23.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\24.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\25.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\26.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\27.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\28.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\29.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\30.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\31.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\32.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\33.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\34.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\35.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\36.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\37.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\38.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\39.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\40.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\41.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\42.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\43.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\44.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\45.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\46.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\47.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\48.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\49.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\50.GIF
Can't read input file!
DEBUG: try to get filename
DEBUG: _filename = C:\Documents and Settings\Jon\workspace\Poker\src\img\51.GIF
Can't read input file!
[Ace of Clubs, Two of Clubs, Three of Clubs, Four of Clubs, Five of Clubs, Six of Clubs, Seven of Clubs, Eight of Clubs, Nine of Clubs, Ten of Clubs, Jack of Clubs, Queen of Clubs, King of Clubs, Ace of Diamonds, Two of Diamonds, Three of Diamonds, Four of Diamonds, Five of Diamonds, Six of Diamonds, Seven of Diamonds, Eight of Diamonds, Nine of Diamonds, Ten of Diamonds, Jack of Diamonds, Queen of Diamonds, King of Diamonds, Ace of Hearts, Two of Hearts, Three of Hearts, Four of Hearts, Five of Hearts, Six of Hearts, Seven of Hearts, Eight of Hearts, Nine of Hearts, Ten of Hearts, Jack of Hearts, Queen of Hearts, King of Hearts, Ace of Spades, Two of Spades, Three of Spades, Four of Spades, Five of Spades, Six of Spades, Seven of Spades, Eight of Spades, Nine of Spades, Ten of Spades, Jack of Spades, Queen of Spades, King of Spades]



 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The string "Can't read input file!" doesn't appear in the code you posted. Therefore that output isn't coming from the code you posted.
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:The string "Can't read input file!" doesn't appear in the code you posted. Therefore that output isn't coming from the code you posted.


Yes it is. He followed your advice to not ignore exceptions and ImageIO.read() throws an IOException with that message.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:

Paul Clapham wrote:The string "Can't read input file!" doesn't appear in the code you posted. Therefore that output isn't coming from the code you posted.


Yes it is. He followed your advice to not ignore exceptions and ImageIO.read() throws an IOException with that message.



Really? That's a very un-traditional error message, I've never seen one like that. Anyway displaying the stacktrace (e.printStackTrace()) would be a better strategy.
 
Greenhorn
Posts: 25
Oracle PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add ".GIF" to the end of the line 54;
It should be
 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From javax.imageio.ImageIO source code:



I guess they got their summer intern to write this one!
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Manjula Weerasinghe wrote:add ".GIF" to the end of the line 54;
It should be



Changing code to the following still results in an exception:

 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Luigi Plinge wrote:From javax.imageio.ImageIO source code:



I guess they got their summer intern to write this one!



lol, well I asked Oracle just in case they can provide more information, and this seems to be a problem with storing Images in an array[], which is not possible, thus the error message is not clear enough to newbies like me.

Now I am using an ArrayList<Image> to store the images, and, although I still haven't coded the viewer, data seems to be going into the ArrayList, because I have walked through the code:



I'm not yet sure how to get to the subdirectory that is relative to the current directory, and, have a problem ensuring that the image icons have consistent dimensions in terms of pixels (e.g. all images to confirm to 75 x 100 pixels, because it's tough to do this manually).
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jon Camilleri wrote:

Luigi Plinge wrote:From javax.imageio.ImageIO source code:



I guess they got their summer intern to write this one!



lol, well I asked Oracle just in case they can provide more information, and this seems to be a problem with storing Images in an array[], which is not possible, thus the error message is not clear enough to newbies like me.

Now I am using an ArrayList<Image> to store the images, and, although I still haven't coded the viewer, data seems to be going into the ArrayList, because I have walked through the code:



I still have a problem ensuring that the image icons have consistent dimensions in terms of pixels (e.g. all images to confirm to 75 x 100 pixels, because it's tough to do this manually), however this is not a big issue at this stage.

I am also wondering whether the line marked above is superfluous (copied and pasted from somewhere), because it does not seem to make sense to read into _image twice, and, the object seems to be getting a value even when I comment it out. However, an image reader is still in the works, so I can't be sure until I actually read my icons off getCardIcons().




 
Shiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic