简体   繁体   English

无法在其他类中调用方法。 (爪哇/ GWT)

[英]Unable to call method in Different class . (Java/GWT)

I am writing a code in GWT client Side. 我正在GWT客户端编写代码。 I am getting a error in calling a method in other class. 在其他类中调用方法时出现错误。 Please see the below code. 请参见下面的代码。

        public class QTypeBox extends Composite {
            public FlexTable textTypeFlexTable;

        public QTypeBox() {

            textTypeFlexTable = new FlexTable();
            initWidget(textTypeFlexTable);
            textTypeFlexTable.setSize("520px", "100px");                                
            //addImageTypeBox(0);
            //addTextBox(2);
            //addMatchPairBow(9);

        }

        public int getPosition(){
            int i =textTypeFlexTable.getRowCount();
            return i;
        }       
        public void addImageTypeBox(int i) {
            // TODO Auto-generated method stub
            Image image = new Image((String) null);
            textTypeFlexTable.setWidget(0, 0, image);
        }
         public void addMP(int i){
            Label lblColumnA = new Label("Column A");
            textTypeFlexTable.setWidget(i, 0, lblColumnA);

            Label lblColumnB = new Label("Column B");
            textTypeFlexTable.setWidget(i, 4, lblColumnB);
         }
    }

////

    public class Test extends Composite {

            private FlexTable flexTable_2;

            public Test() {
            initWidget(flexTable_2);


            QTypeBox qTypeBox = new QTypeBox();
            qTypeBox.addMP(4);//**<<<<--------------**


           }

In class Test , where i have marked like <<<<---------- is showing me error. 在Test类中,我已标记为<<<< ----------向我显示错误。

The method addMP(int) is undefined for the type QTypeBox

I checked the Hint, It asked me to create a method addMP(int) in QtypeBox . 我检查了提示,它要求我在QtypeBox创建方法addMP(int)。 If i do this , again it ask me to change the name of Existing method addMP 如果我这样做,再次要求我更改现有方法addMP的名称

Can anyone guide where i am doing it wrong. 任何人都可以指导我在哪里做错了。

Your code is clean. 您的代码是干净的。 The error is due to eclipse not recognizing the class and its methods. 该错误是由于日食无法识别该类及其方法所致。

Any one of this steps will resolve your problem 此步骤中的任何一个都可以解决您的问题

  • Clean Build your project 清洁构建您的项目
  • Refresh your project 刷新您的项目
  • Delete the classes manually and clean build your project 手动删除类并清理构建项目
  • Close and open your eclipse If none of the above works then the below one will surely resolve your problem 关闭并打开月食如果以上方法均无效,那么以下方法肯定会解决您的问题
  • Delete and recreate your classes again 再次删除并重新创建您的课程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM