• 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

Adding Multiple ImageView

 
Greenhorn
Posts: 11
Netbeans IDE Python VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just trying to add multiple images view to the Box but still no success... where i am going Wrong?

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

M.Aamir khan wrote:... still no success...


You need to TellTheDetails <- that's a link

Are any Exceptions thrown? I see a catch block with only e.getMessage() which returns a String that you don't do anything with. I would suggest replacing that with e.printStackTrace().

You do know that arrays need to be innitialized before they are used, don't you?
 
M.Aamir khan
Greenhorn
Posts: 11
Netbeans IDE Python VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh my Bad ,,, i didn't init the array,,, thanks for the Hint...

but we can not predict the size of the input to init the array ..
 
M.Aamir khan
Greenhorn
Posts: 11
Netbeans IDE Python VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are any Exceptions thrown?



No, There is no Exception thrown program is running fine but not adding any image to ImageView

and yes i initialize the array with but we know the size of input is unpredictable and once i initialize the array, lets say 10 in this case so it will fill with not more than 10 images and then here is the pro with this Code



once you clear the ImageView it will not take data again because its still having some garbage i thought
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

M.Aamir khan wrote:but we can not predict the size of the input to init the array ..


Good use case for a List or other Collection. Have you dicovered the Oracle tutorials? Trail: Collections.
 
M.Aamir khan
Greenhorn
Posts: 11
Netbeans IDE Python VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Good use case for a List or other Collection.



Yup , Working Fine Now..

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

New to this forum!

The final solution worked for me, thank you! And I have this follow up question, if someone would like to tackle:

Looking at the code below, why do I need to initialize each ImageView array element twice? I initialized the whole array on line 16, which means I created 10 instances of ImageView. But if I don't initialize each one once again on line 20, I get a run time exception. Why do I need to do the exact same thing twice?

It seems I don't understand something fundamental about how Java initializes arrays of objects. Could someone explain this to me?

This is the error message:


Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
       at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
       at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
       at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
       at myJavaFx.start(myJavaFx.java:21)
       at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
       at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
       at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
       at java.security.AccessController.doPrivileged(Native Method)
       at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
       at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
       at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
       at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
       ... 1 more

Thanks very much.


 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This line
Creates as array of 10 empty ImageView sized buckets.

Then
puts a new instance of an ImageView in the bucket at index i.

Make sense?
 
Marshal
Posts: 79239
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I suggest you consider an array initialiser intead of new Foo[123].
ImageView[] images = {new ImageView(), new ImageView(), ...};
That might be too longwinded for you to write here, but it will ensure you have no nulls in your array. You do however appear to be initiaising the array elements in the loop, so it is surprising that you are getting that Exception in your line 21. Try a line 20½:-
System.out.printf("ImageView != null %b%nImage != null %b%n", imageView[i], image);
That shou‍ld pick up any nulls. The %b tag can test a non‑Boolean object for nullity.
Don't use number literals in the for loop if at all possible. Not ...i < 10;... but ...i < myArray.length;...
 
hoji afzal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Yes, it does make sense now!

I guess the clue is ImageView[10] versus ImageView().

Only ImageView() calls the constructor.

And I used a hard coded integer as a loop counter to make is easier for you to follow my code. Otherwise I avoid raw numbers there. Thanks for the suggestion.

Thank you very much!

Cheers
 
hoji afzal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Campbell, I got the exception when I DIDN'T call the constructor. Once I used line 16 20 the code worked fine!
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hoji afzal wrote:And Campbell, I got the exception when I DIDN'T call the constructor. Once I used line 1620 the code worked fine!

Aaaaaaaaaah! That makes it clear.
I shall edit the post for you.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic