java - Codename one: Why am I getting "/ by zero" when trying to scale an image -


i trying scale image fit screen width.

therefore trying load imported multi image in beforeterminalgui method here:

@override protected void beforeterminalgui(form f) {     imageviewer iv = findimageviewer(f);      image = fetchresourcefile().getimage("stillstand.png");     i.scaledwidth(iv.getwidth());      iv.setimage(i); } 

which created when clicked beforeshow event in gui builder. (i saved gui builder after doing so)

but getting error:

java.lang.arithmeticexception: / 0     @ com.codename1.impl.javase.javaseport.scalearray(javaseport.java:3505)     @ com.codename1.impl.javase.javaseport.scale(javaseport.java:3497)     @ com.codename1.ui.image.scale(image.java:961)     @ com.codename1.ui.image.scaledimpl(image.java:931)     @ com.codename1.ui.image.scaled(image.java:896)     @ com.codename1.ui.image.scaledwidth(image.java:835)     @ com.codename1.ui.encodedimage.scaledwidth(encodedimage.java:536)     @ userclasses.statemachine.beforeterminalgui(statemachine.java:37)     @ generated.statemachinebase.beforeshow(statemachinebase.java:537)     @ com.codename1.ui.util.uibuilder.showform(uibuilder.java:2512)     @ com.codename1.ui.util.uibuilder.showcontainerimpl(uibuilder.java:2334)     @ com.codename1.ui.util.uibuilder.showcontainer(uibuilder.java:2214)     @ com.codename1.ui.util.uibuilder$formlistener.actionperformed(uibuilder.java:2900)     @ com.codename1.ui.util.eventdispatcher.fireactionevent(eventdispatcher.java:338)     @ com.codename1.ui.form.actioncommandimpl(form.java:1415)     @ com.codename1.ui.form.dispatchcommand(form.java:1381)     @ com.codename1.ui.sidemenubar$commandwrapper$showwaiter.run(sidemenubar.java:1611)     @ com.codename1.ui.display.processserialcalls(display.java:1147)     @ com.codename1.ui.display.edtloopimpl(display.java:1091)     @ com.codename1.ui.display.mainedtloop(display.java:994)     @ com.codename1.ui.runnablewrapper.run(runnablewrapper.java:120)     @ com.codename1.impl.codenameonethread.run(codenameonethread.java:176) 

same happens methods i.scale (..),i.scaledheight(..) whenever run app , want switch terminalgui.

i new codenameone , welcome.

the problem iv.getwidth() should use iv.getimage().getwidth(), return width of imageviewer's image , not width of component itself. check existence of image stillstand.png before scaling it.

@override protected void beforeterminalgui(form f) {     imageviewer iv = findimageviewer(f);     image = resources.openlayered("/theme").getimage("stillstand.png");     if (i != null) {         i.scaledwidth(iv.getimage().getwidth());         iv.setimage(i);     } else {         system.out.println("image not found");     } } 

another way scale image fit screen width doing this:

@override protected void beforeterminalgui(form f) {     imageviewer iv = findimageviewer(f);     image = resources.openlayered("/theme").getimage("stillstand.png");     if (i != null) {         iv.setimage(i.scaledwidth(display.getinstance().getdisplaywidth()));     } else {         system.out.println("image not found");     } } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -