Codenameone 尝试显示内容时出错:布局不';不支持添加参数

Codenameone 尝试显示内容时出错:布局不';不支持添加参数,codenameone,Codenameone,每当我尝试向表单中添加组件时,都会出现此错误我使用的函数如下: 此功能允许我在用户登录时初始化移动应用程序的主视图 private void initMainView() { //---------------------------------------------------------------------------------------- User user = Controller.getThisUser(); /

每当我尝试向表单中添加组件时,都会出现此错误我使用的函数如下: 此功能允许我在用户登录时初始化移动应用程序的主视图

private void initMainView() {
        //----------------------------------------------------------------------------------------        
        User user = Controller.getThisUser();
        //----------------------------------------------------------------------------------------
        theme = UIManager.initFirstTheme("/theme");

        Form mainForm = new Form();


        final Command profileCommand = new Command("Mon Profil") {

            public void actionPerformed(ActionEvent evt) {
                mainForm.getContentPane().removeAll();
                ProfilController profilController = new ProfilController();
                profilController.initialize();
                mainForm.addComponent(BorderLayout.CENTER, profilController.getView());
                mainForm.revalidate();
            }
        };


        Image img = utilService.getImageProfilFromURL(user.getUrl());
        mainForm.addCommand(new Command("", img));
        mainForm.addCommand(profileCommand);

        Command c = new Command("Modules");
        Label l = new Label("Acceder à") {

            public void paint(Graphics g) {
                super.paint(g);
                g.drawLine(getX(), getY() + getHeight() - 1, getX() + getWidth(), getY() + getHeight() - 1);
            }
        };
        l.setUIID("Separator");
        c.putClientProperty("SideComponent", l);



        mainForm.addCommand(c);

        mainForm.addCommand(new Command("Profile", theme.getImage("all friends.png")) {


        });

        Toolbar toolBar = mainForm.getToolbar();
        toolBar.addCommandToRightBar("", theme.getImage("notifDemande.png"), (ActionListener) (ActionEvent evt) -> {
            mainForm.getContentPane().removeAll();          
            mainForm.revalidate();
        });
        toolBar.addCommandToRightBar("", theme.getImage("notifMessage.png"), (ActionListener) (ActionEvent evt) -> {
            mainForm.getContentPane().removeAll();            
            mainForm.revalidate();
        });
        toolBar.addCommandToRightBar("", theme.getImage("notifAccept.png"), (ActionListener) (ActionEvent evt) -> {
            mainForm.getContentPane().removeAll();            
            mainForm.revalidate();
        });

        mainForm.addCommand(new Command("Forum", theme.getImage("photos icon.png")) {

        });

        mainForm.addCommand(new Command("Evenement", theme.getImage("wall post.png")) {


        });

        mainForm.addCommand(new Command("Equipement", theme.getImage("wall post.png")) {


        });

        Command c1 = new Command("ACTIONS");
        Label l1 = new Label("ACTIONS") {

            public void paint(Graphics g) {
                super.paint(g);
                g.drawLine(getX(), getY() + getHeight() - 1, getX() + getWidth(), getY() + getHeight() - 1);
            }
        };
        l1.setUIID("Separator");
        c1.putClientProperty("SideComponent", l1);
        mainForm.addCommand(c1);

        mainForm.addCommand(new Command("Parametres de profil", theme.getImage("wall post.png")) {


        });

        mainForm.addCommand(new Command("Logout") {

            public void actionPerformed(ActionEvent evt) {

            }
        });

        mainForm.addCommand(new Command("Quitter") {

            public void actionPerformed(ActionEvent evt) {
                Display.getInstance().exitApplication();
            }
        });



        mainForm.show();
    }
这是profilController控制器中的初始化函数:

@Override
    public void initialize() {
        Container c = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        c.setScrollableY(true);


        User u = this.getThisUser();

        Container changec = new Container(new BoxLayout(BoxLayout.Y_AXIS));

        Container entete = new Container(new BoxLayout(BoxLayout.X_AXIS));
        //c.add(theme.getImage(t.getImg()));
        Image img = utilService.getImageProfilFromURL(u.getUrl());
        Label nt = new Label(u.getNom()+" "+u.getPrenom());
        entete.add(img).add(nt);
        //c.add(entete);        
        Button journal = new Button("Journal");


        Button apropos = new Button("A Propos");

        Button album = new Button("Album");

        c.add(entete);
        c.add(journal);
        c.add(apropos);
        c.add(album);
        c.add(changec);
        //------------
        this.rootContainer.removeAll();
        this.rootContainer.add(BorderLayout.NORTH, c);
        this.rootContainer.revalidate();
    }
我是新来的代号一,我不知道该怎么解决这个问题,有什么想法吗

编辑: 以下是控制台输出:

java.lang.IllegalStateException: Layout doesn't support adding with arguments: com.codename1.ui.layouts.FlowLayout
    at com.codename1.ui.layouts.Layout.addLayoutComponent(Layout.java:66)
    at com.codename1.ui.Container.addComponent(Container.java:746)
    at com.codename1.ui.Form.addComponent(Form.java:1548)
    at com.mycompany.myapp.MyApplication$2.actionPerformed(MyApplication.java:182)
    at com.codename1.ui.SideMenuBar$CommandWrapper.actionPerformed(SideMenuBar.java:1809)
    at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)
    at com.codename1.ui.Button.fireActionEvent(Button.java:563)
    at com.codename1.ui.Button.released(Button.java:605)
    at com.codename1.ui.Button.pointerReleased(Button.java:709)
    at com.codename1.ui.Form.pointerReleased(Form.java:3397)
    at com.codename1.ui.SideMenuBar$8.pointerReleased(SideMenuBar.java:1226)
    at com.codename1.ui.Component.pointerReleased(Component.java:4555)
    at com.codename1.ui.Display.handleEvent(Display.java:2193)
    at com.codename1.ui.Display.edtLoopImpl(Display.java:1156)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:1074)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

您正在调用以下命令:

mainForm.addComponent(BorderLayout.CENTER, profilController.getView());
但您创建的表单如下所示:

Form mainForm = new Form();
您可能应该像这样创建
表单
,因为您的默认布局将是
FlowLayout
,这几乎没有意义:

Form mainForm = new Form(new BorderLayout());
引发异常是因为对于流布局,这是合法语法:

mainForm.addComponent(profilController.getView());

除了Shai的答案,我建议您查找Codename One的布局基础知识,因为这在您未来的开发中将是必不可少的

此处的书面文档:

如果您喜欢观看视频,这是为您准备的: