当我提交代码时,我收到了这个错误。这仅发生在我在课程所需的在线编译器上提交代码时,但是,当我通过InteliJ运行我的代码时,它会正确编译。
主要的java:335:错误:在(!(TeamMember.contains(“Stop”)){^symbol:method contains(String)位置:类TeamMember 1错误时找不到符号
我的课程如下:
主要:
package com.company;
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
String name = "";
String id = "";
ArrayList<TeamMember> list = new ArrayList<>();
while (!(TeamMember.contains("Stop"))) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter the name: ");
name = scan.nextLine();
System.out.println("Please enter the id: ");
id = scan.nextLine();
list.add(new TeamMember(name.toLowerCase(), id));
System.out.println(Main.selectionSort(list));
}
int size = list.size();
for (int j = size; j > (list.size() + 2); j--) {
list.remove(j);
}
}
public static ArrayList<TeamMember> selectionSort(ArrayList<TeamMember> list) {
TeamMember[] teamArray = new TeamMember[list.size()];
for (int i = 0; i < list.size(); i++) {
teamArray[i] = list.get(i);
}
for (int i = 0; i < teamArray.length - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < teamArray.length; j++) {
if (teamArray[j].compareTo(teamArray[minIndex]) < 0) {
minIndex = j;
}
}
TeamMember holder = teamArray[i];
teamArray[i] = teamArray[minIndex];
teamArray[minIndex] = holder;
}
for (int i = 0; i < list.size(); i++) {
list.set(i, teamArray[i]);
}
return list;
}
}
团队成员:
package com.company;
import java.util.ArrayList;
class TeamMember{
private String fullName;
private String idString;
public TeamMember(String name, String id){
fullName = "";
name = name.toLowerCase();
String [] charName = new String[name.length()];
for(int i = 0; i < charName.length; i++){
charName[i] = Character.toString(name.charAt(i));
if(i == 0){
charName[0] = charName[0].toUpperCase();
}
}
for(int i = 0; i < charName.length - 1; i++){
if(charName[i].equals(" ") && !charName[i + 1].equals(" ")){
charName[i + 1] = charName[i + 1].toUpperCase();
}
}
for(int i = 0; i < charName.length; i++){
fullName = fullName + charName[i];
}
idString = id;
}
public static boolean contains(String stop) {
return false;
}
public String getID(){
return idString;
}
public String toString(){
return fullName;
}
public int compareTo(TeamMember other){
if(idString.compareTo(other.getID()) < 0){
return -1;
}
else if(idString.compareTo(other.getID()) > 0){
return 1;
}
else{
return 0;
}
}
}
似乎无法从您的Main
类访问类Team会员
。尝试此代码,因为它应该可以将类放在同一个文件中。
import java.util.Scanner;
import java.util.ArrayList;
public class Main
{
public static void main(String[] args) {
String name = "";
String id = "";
ArrayList<TeamMember> list = new ArrayList<>();
while (!(TeamMember.contains("Stop"))) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter the name: ");
name = scan.nextLine();
System.out.println("Please enter the id: ");
id = scan.nextLine();
list.add(new TeamMember(name.toLowerCase(), id));
System.out.println(Main.selectionSort(list));
}
int size = list.size();
for (int j = size; j > (list.size() + 2); j--) {
list.remove(j);
}
}
public static ArrayList<TeamMember> selectionSort(ArrayList<TeamMember> list) {
TeamMember[] teamArray = new TeamMember[list.size()];
for (int i = 0; i < list.size(); i++) {
teamArray[i] = list.get(i);
}
for (int i = 0; i < teamArray.length - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < teamArray.length; j++) {
if (teamArray[j].compareTo(teamArray[minIndex]) < 0) {
minIndex = j;
}
}
TeamMember holder = teamArray[i];
teamArray[i] = teamArray[minIndex];
teamArray[minIndex] = holder;
}
for (int i = 0; i < list.size(); i++) {
list.set(i, teamArray[i]);
}
return list;
}
}
class TeamMember{
private String fullName;
private String idString;
public TeamMember(String name, String id){
fullName = "";
name = name.toLowerCase();
String [] charName = new String[name.length()];
for(int i = 0; i < charName.length; i++){
charName[i] = Character.toString(name.charAt(i));
if(i == 0){
charName[0] = charName[0].toUpperCase();
}
}
for(int i = 0; i < charName.length - 1; i++){
if(charName[i].equals(" ") && !charName[i + 1].equals(" ")){
charName[i + 1] = charName[i + 1].toUpperCase();
}
}
for(int i = 0; i < charName.length; i++){
fullName = fullName + charName[i];
}
idString = id;
}
public static boolean contains(String stop) {
return false;
}
public String getID(){
return idString;
}
public String toString(){
return fullName;
}
public int compareTo(TeamMember other){
if(idString.compareTo(other.getID()) < 0){
return -1;
}
else if(idString.compareTo(other.getID()) > 0){
return 1;
}
else{
return 0;
}
}
}
问题内容: 当代码到达递归调用增量时,我收到错误找不到符号,我不知道为什么?这是增量代码。任何帮助将不胜感激。 编辑:我真的是Java的新手,所以可以做的答案越基本越好。好的,所以我收到的错误是:BigNatural.java.35:找不到符号符号方法增量()位置:类java.lang.String temp.increment() 并在此处清除所有其他问题,是整个代码。 }公共类BigNatur
问题内容: 嘿,我刚开始我的第一本Java编程书籍,所以这应该很容易解决。弄乱我对条件句的新知识,发现标题错误。 这是代码: 当我尝试编译时: 问题答案: 错误消息告诉您变量“输入”在您的作用域中不存在。您可能想使用Scanner对象,但将其命名为“ x”,而不是“ input”。 应该修复它。
我一直在尝试使用Eclipse和Forge编译Minecraft mod,但我只是遇到错误,我想这是与链接Minecraft库有关,但不确定这是我的代码 我正在遵循一个指南,应该在最后得到一条“构建成功”的消息。指南是https://blog.usejournal.com/a-beginners-guide-to-modding-Minecraft-9A42536495F6 这里有个错误
嘿,我刚刚开始我的第一本关于Java的编程书,所以这应该是一个简单的修复。把我对条件句的新知识弄得乱七八糟的,结果我得到了标题错误。 代码如下: 当我尝试编译:
我有这样的代码:获取一个文本文件,并将其转换为字符串,然后将字符串的部分分离为ArrayList的不同元素。 然而,当我试图编译它时,它给了我两个错误: javac Message.java Message.java:31:找不到符号symbol:变量输入位置:类消息while(input.HasNextLine()){^Message.java:32:找不到符号symbol:变量输入位置:类消息
问题内容: 美好的一天,我在同一目录中有两个类Map和Field。我成功地编译了Field.java,但是当我编译Map.java时,我得到了: 这是两个类的代码: 对于Field.java(如有必要): 我分别编译了Field.java和Map.java:javac Field.java没有返回任何错误,但是javac Map.java返回了以上错误。 问题答案: 我仍然不清楚您的问题到底在哪里