1

This is the same problem as I posted Dec 2022: "CodenameOne Cannot Add Image to Button Using GUI Builder". It hasn't been a problem on the two most recent projects I've deployed because I haven't used images (I gave up on getting this fixed).

I created this new post because I know a little more about how CNO works and I think I posted some incorrect information last time.

So my project is NOT using CSS, and I am using the new GUI Builder. In the GUI Builder I add an image to a button by clicking the "Add Image" icon at the top-right. I navigate to the image source (a png file) and add it.

Then I go to the button's Property Inspector and click on "Icon [Pick Image]". I choose "res file" and then click on the newly added image source. So far so good: I can now see the icon image in the form. I save the GUI Builder form, build the project and run the simulator and wow, it shows my button image!

But now (without changing anything) I re-run the simulator and my button image is gone!

If I go back to the button's Property Inspector and attempt to add the image I see that it's gone from there too.

So for some reason the image is getting deleted from the res file during the build. I have included the two output files, one from the first build and also from the second.

I really need a fix for this: Shai, is there some way we can schedule a phone call for paid support?

Here is the output from the 1st build, and Here is the output from the 2nd build.

Doug Sisco
  • 121
  • 9
  • Based on the project output you do use CSS. I'm guessing it's conflicting with the resource editor as you have two resource files. How did you disable CSS in the project? – Shai Almog May 20 '23 at 05:40
  • In the project CodenameOne settings under Advanced Settings, CSS it reads "CSS is not currently activated." – Doug Sisco May 20 '23 at 12:33
  • OK. But CSS shouldn't have been enabled to begin with if you created this as an Ant project. Why is it running? Is there a CSS directory in the project directory? Is the file you're editing `C:\Users\admin\Desktop\TravelerBarCode2\src\theme.res` ? If so it seems pretty clear that it's overriden by CSS. – Shai Almog May 21 '23 at 02:00
  • Sorry, I don't understand what you are asking about 'it' running. Yes, there is a src\theme.res, and I will delete it and see if it helps. But how can a CNO setting that clear states that CSS is NOT enabled be overridden by the presence of a folder? – Doug Sisco May 21 '23 at 14:59
  • Look through the code and check if that theme.res file is referenced anywhere in the code. If you derive Lifecycle make sure you override `getThemeName()` and return the name of your actual theme instead of `"/theme"` (without the `.res` extension). – Shai Almog May 22 '23 at 01:58
  • I searched my project 'theme.res' but only found it in build.xml (which you can access from https://dougsisco.com/1777/build.xml. I am not deriving from Lifecycle. Can you tell anything from my build.xml? – Doug Sisco May 22 '23 at 21:12
  • In the `build.xml` file find `` and remove the depends: ``. Delete the CSS directory and the `theme.res` file. If the problem persists I'd like you to look at the source file. Does it change or is the resource file losing the image you've set into it? – Shai Almog May 23 '23 at 02:08
  • I removed the 'depends' and deleted the CSS directory. However if I delete src/theme.res then the build fails with "java.io.IOException: /theme.res not found". If I leave the theme.res in place, the project builds ok and (so far) my resources are staying intact. I'll post again later today after I've done a few more builds. – Doug Sisco May 23 '23 at 11:59
  • I guess the CSS in the build XML overrode your resource file every time you ran the application. – Shai Almog May 25 '23 at 02:18

1 Answers1

0

Thanks to Shai for this answer.. I don't quite understand what was going on, but at last my button images aren't deleted with every build.

The fix was to edit the build.xml file find and remove the depends: .

Doug Sisco
  • 121
  • 9