【问题标题】:The method ***** is undefined for the type ************ 类型的方法 ***** 未定义
【发布时间】:2014-04-10 04:19:05
【问题描述】:

我是这个论坛的新手,首先我要感谢您审阅我的问题。

我收到此消息:CreandoFunciones 类型的方法 CreandoFunciones() 未定义。我是新的@Java,我尝试了一些东西,但没有。

任何帮助将不胜感激。谢谢

package funciones;
import java.util.Scanner;

public class Funciones1 {

private static Scanner scan;

public static void main(String[] args) 
{
    CreandoFunciones link = new CreandoFunciones();
    {

        int menu;
        scan = new Scanner(System.in);
        System.out.println("Opción: ");
        menu = scan.nextInt();

        switch(menu)
        {
        case 1: 
            link.CreandoFunciones();
            break;
        case 2:
               System.out.println("C'est la vie!");
               break;
        case 3:
                System.out.println("Alors on danse!");
                break;
        default: System.out.println("Owned.");      
        }

}
  }
}


package funciones;

public class CreandoFunciones {

public CreandoFunciones()
{
        System.out.println("Testing");
}

}

【问题讨论】:

  • 你认为错误信息试图告诉你什么?
  • CreandoFunciones 中没有名为CreandoFunciones 的方法。你所拥有的是构造函数......你不会像那样调用构造函数。只需执行 CreandoFunciones link = new CreandoFunciones() 你应该会看到“Testing”
  • BTW CreandoFunciones 在技术上是错误的。你想要创建的是metodos,因为类中的“函数”被称为“方法”。

标签: java eclipse methods undefined


【解决方案1】:

CreandoFunciones() 是类的构造函数,而不是通常的方法。所以你不能像link.CreandoFunciones();那样打电话。要在链接 1 中执行操作,请在类中创建一个单独的方法。

【讨论】:

  • 该死,这么快o_o...谢谢您的回复....如果我将“public CreandoFunciones()”更改为“public void CreandoFunciones1()”然后我这样称呼它怎么办“链接.CreandoFunciones1();” ?
猜你喜欢
  • 1970-01-01
  • 2022-12-23
  • 2016-06-07
  • 2021-06-19
  • 2014-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多