如果 java class 位于不同路径,则调用构造函数时出现问题
Problem at calling a constructor if the java class is in a different path
我想将 java classes 保存在名为 类 的文件夹中,因此在 NetBeans 上,我创建了该文件夹,然后将其保存在 class 调用了 Jugadores.java,但在调用主 class 上调用名为 regisPlayer 的构造函数时遇到问题。
NetBeans 说:
找不到符号
symbol:class regisPlayer
位置:class义务
这是我的主要class
package obligatorio;
import java.util.*;
import obligatorio.classes.*;
public class Obligatorio {
public static void main(String[] args) {
Jugadores();
}
static void Jugadores() {
Scanner in = new Scanner(System.in);
System.out.println("Player Name ");
String Name = in.nextLine();
System.out.println("Age Player ");
int Edad = in.nextInt();
Jugadores player = new regisPlayer(Name, Edad); // On this line says than can not find the symbol regisPlayer
}
}
这是我的classJugadores.java
package obligatorio.classes;
public class Jugadores {
private String nombre;
private int edad;
public void regisPlayer(String Nombre, int Edad) {
this.nombre(Nombre);
this.edad(Edad);
}
public void nombre(String Nombre) {
nombre = Nombre;
}
public void edad(int Edad) {
edad = Edad;
}
}
我不知道这可能是什么问题,我正在学习Java。我试图解决在 Jugadores.java 中添加名称包 obligatorio.classes 然后在我的主 class 上调用它的问题,但我没有工作。
package obligatorio.classes;
public class Jugadores {
private String nombre;
private int edad;
public Jugadores(String nombre, int edad) { //this is a constructor
this.nombre = nombre;
this.edad = edad;
}
public void setNombre(String Nombre) { //only need setters if you plan to change it
nombre = Nombre;
}
public void setEdata(int Edad) {//only need setters if you plan to change it
edad = Edad;
}
}
这样使用:
Jugadores player = new Jugadores("name example", "edad example");
我想将 java classes 保存在名为 类 的文件夹中,因此在 NetBeans 上,我创建了该文件夹,然后将其保存在 class 调用了 Jugadores.java,但在调用主 class 上调用名为 regisPlayer 的构造函数时遇到问题。 NetBeans 说:
找不到符号
symbol:class regisPlayer
位置:class义务
这是我的主要class
package obligatorio;
import java.util.*;
import obligatorio.classes.*;
public class Obligatorio {
public static void main(String[] args) {
Jugadores();
}
static void Jugadores() {
Scanner in = new Scanner(System.in);
System.out.println("Player Name ");
String Name = in.nextLine();
System.out.println("Age Player ");
int Edad = in.nextInt();
Jugadores player = new regisPlayer(Name, Edad); // On this line says than can not find the symbol regisPlayer
}
}
这是我的classJugadores.java
package obligatorio.classes;
public class Jugadores {
private String nombre;
private int edad;
public void regisPlayer(String Nombre, int Edad) {
this.nombre(Nombre);
this.edad(Edad);
}
public void nombre(String Nombre) {
nombre = Nombre;
}
public void edad(int Edad) {
edad = Edad;
}
}
我不知道这可能是什么问题,我正在学习Java。我试图解决在 Jugadores.java 中添加名称包 obligatorio.classes 然后在我的主 class 上调用它的问题,但我没有工作。
package obligatorio.classes;
public class Jugadores {
private String nombre;
private int edad;
public Jugadores(String nombre, int edad) { //this is a constructor
this.nombre = nombre;
this.edad = edad;
}
public void setNombre(String Nombre) { //only need setters if you plan to change it
nombre = Nombre;
}
public void setEdata(int Edad) {//only need setters if you plan to change it
edad = Edad;
}
}
这样使用:
Jugadores player = new Jugadores("name example", "edad example");