totalcross application with images, when deploying for windows CE does not work

Asked

Viewed 115 times

3

When I deploy my application to Windows CE that contains images on the screen or in Buttons no element is displayed, but in the emulator works normally. When I remove images it works normally.

public class Teste extends Container {
    private ScrollContainer sc;
    private Container contTopo,contRodape;
    private Edit edtIdentificador;
    private Button btIdentificador,btFinalizar;
    private Label lblMultiplicacao,lblMensagem;

    public void initUI() {

        setBackColor(Colors.GRAY);
        setBorderStyle(BORDER_SIMPLE);

        try {
            edtIdentificador = new Edit();
            edtIdentificador.caption = "Insira o identificador";
            edtIdentificador.setFont(Font.getFont("Lato Medium", false, edtIdentificador.getFont().size -2));
            edtIdentificador.setBackForeColors(Color.BLACK, Color.BLACK);
            edtIdentificador.requestFocus();

            btIdentificador =
                  new Button(
                      new Image("images/barra.png")
                          .hwScaledFixedAspectRatio((int) (Settings.screenDensity * 24), true));

            btIdentificador.setBorder(Button.BORDER_NONE);
            btIdentificador.setBackForeColors(Color.WHITE, Color.WHITE);

            contTopo = new Container();
            contTopo.setBackForeColors(Color.WHITE, Color.WHITE);
            add(contTopo, CENTER, TOP, PARENTSIZE, PARENTSIZE+15);
            contTopo.add(edtIdentificador, LEFT+170, TOP, PARENTSIZE+60, PARENTSIZE+80);
            contTopo.add(btIdentificador, RIGHT, TOP, PARENTSIZE+20, PARENTSIZE+100);

            lblMensagem = new Label("Adicione um indicador para listagem",CENTER);
            lblMensagem.setBackForeColors(Colors.GRAY,0x999999 );
            lblMensagem.setFont(Font.getFont("Lato Medium", false, lblMensagem.getFont().size -5));
            add(lblMensagem,CENTER,CENTER,PARENTSIZE,PARENTSIZE+10);


            contRodape = new Container();
            contRodape.setBackForeColors(Colors.GREEN, Color.WHITE);
            add(contRodape, CENTER, BOTTOM, PARENTSIZE, PARENTSIZE+10);  
            btFinalizar = new Button("Finalizar");
            btFinalizar.transparentBackground = true;
            contRodape.add(btFinalizar, RIGHT, CENTER, (int) (Settings.screenDensity * 100), PREFERRED+20);
          } catch (IOException | ImageException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
         }
    }
}

3 answers

2

The images were in a images folder, after placing the images folder inside the source foolder "src/main/Resources" the images appeared in the application

2


I know you already solved your problem, but it costs nothing to explain what happened for future reference.

The images were reachable in Java code. This means that

  1. they were in the classpath implementing the tc.Launcher, or
  2. they were in the CWD

however, it does not necessarily happen on the device. When you turn the tc.Deploy, no matter where, it will create the .tcz relating to its code and its Assets to be interpreted by the Totalcross VM on the device.

There are two ways to create .tcz:

  1. passing as argument the way to the .class of the main class (the one which extends MainWindow)
  2. passing as argument a the way a .jar

The .jar can be used to create a .tcz or to create the application itself. To create the application, the file name needs to be equal to the name of the class extending MainWindow (directly or indirectly). For example, if I have a .jar called Marmota.jar, and has some class called Marmota (package independent) that extends MainWindow, then the tc.Deploy will generate an executable.

In the first mode, the tc.Deploy will traverse in depth, from the specified class, all the dependencies that it needs to insert in the .tcz. By dependencies understand:

  1. classes whose methods are called
  2. files whose names can be solved in statically populated strings *

*: I don’t know if you will search all strings, or just strings related to method calls with filenames

Thus, classes and Assets which are not used by the application will be ignored.

When you tell me to tc.Deploy from the .jar, no dependency processing and all input of the .jar will be increased in the .tcz.


In your case, you were using the Totalcross from the Maven. The Maven leads to the classpath only the main content, both the compiled and the Assets. The standard of a Maven project is:

proj/
     |
     +- src/
     |      |
     |      +- main/
     |              |
     |              +- java/
     |              |
     |              +- resources/
     +- target/

What is inside of src/main/java will be compiled and its result will be target, respecting the packages. Already the contents of src/main/resources will simply be copied to target. The moment you put the briefcase images inside resources, is now integrated into target and thus became part of the classpath. While she was at the root of the project, she was not part of the classpath, however, as in the Maven CWD is the root of the project, it was accessible at the Java level.

An interesting alternative to whether a file can be packaged inside the .tcz is simply to rotate a mvn package command line and check if the file is inside the .jar generated. Another is to rotate the tc.Deploy with the option /t, in which he tests the .class and lists all the files that would be sent to .tcz.

If you want a deeper reading:

  • Excellent reply! it was very detailed some things I did not understand. Thank you!

1

I saw your code there and I went to test it on my pc and it worked, I go my code here so you see how it turned out and check with your code to see if there’s something different.

public class Teste extends Container{ Private Container scrollsc; Private container contTopo,contRodape; private edit edIdentifier; Private button btIdentificador,btFinalizar; Private label LBL;

   public void initUI() {

       setBackColor(0xDDDDDD);
       setBorderStyle(BORDER_SIMPLE);

       try {
           edtIdentificador = new Edit();
           edtIdentificador.caption = "Insira o identificador";
           edtIdentificador.setFont(Font.getFont("Lato Medium", false, edtIdentificador.getFont().size -2));
           edtIdentificador.setBackForeColors(Color.BLACK, Color.BLACK);
           edtIdentificador.requestFocus();

           btIdentificador =
                 new Button(
                     new Image("images/barra.png")
                         .hwScaledFixedAspectRatio((int) (Settings.screenDensity * 24), true));

           btIdentificador.setBorder(Button.BORDER_NONE);
           btIdentificador.setBackForeColors(Color.WHITE, Color.WHITE);

           contTopo = new Container();
           contTopo.setBackForeColors(Color.WHITE, Color.WHITE);
           add(contTopo, CENTER, TOP, PARENTSIZE, PARENTSIZE+15);
           contTopo.add(edtIdentificador, LEFT+170, TOP, PARENTSIZE+60, PARENTSIZE+80);
           contTopo.add(btIdentificador, RIGHT, TOP, PARENTSIZE+20, PARENTSIZE+100);

           lblMensagem = new Label("Adicione um indicador para listagem",CENTER);
           lblMensagem.setBackForeColors(0xDDDDDD,0x999999 );
           lblMensagem.setFont(Font.getFont("Lato Medium", false, lblMensagem.getFont().size -5));
           add(lblMensagem,CENTER,CENTER,PARENTSIZE,PARENTSIZE+10);


           contRodape = new Container();
           contRodape.setBackForeColors(Color.GREEN, Color.WHITE);
           add(contRodape, CENTER, BOTTOM, PARENTSIZE, PARENTSIZE+10);
           btFinalizar = new Button("Finalizar");
           btFinalizar.transparentBackground = true;
           contRodape.add(btFinalizar, RIGHT, CENTER, (int) (Settings.screenDensity * 100), PREFERRED+20);
         } catch (Exception e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
        }
   }

}

I didn’t understand why Slack only put organized from the initUI, but this is the code that generated the apk was this one, if it still gives error of a look at pom.xml maybe there is something wrong there. I hope I’ve helped.

  • 2

    The problem was my folder structure, it looked like this: proj/ | +- src/ | | | +-main/ | | | +-java/ | | | +- images/ +- target/ Whereas the correct one was like this(Explained by Jefferson Quesado): proj/ | +-src/ | | | +-main/ | | | +-java/ | | | -Resources/ | | | +-images/ +-target/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.