Java 类型“”的未定义的方法indexOf

Java 类型“”的未定义的方法indexOf,java,file,java.util.scanner,indexof,Java,File,Java.util.scanner,Indexof,我目前还不熟悉编码和上课,我不知道这里的问题是什么,但我正在尝试从一个单独的文本文件中阅读和挑选特定的信息。非常感谢您的帮助 您调用没有显式实例的indexOf,因此java假设this,这里this属于Marathon类型,它没有indexOf(它也必须是静态的,因为main是静态的) 我假设您希望当前行中的,索引。为此,您必须首先使用String line=Stats.nextLine()获取所述行,然后使用line.indexOf(“,”)搜索,“”。错误是不言自明的,Marathon没有

我目前还不熟悉编码和上课,我不知道这里的问题是什么,但我正在尝试从一个单独的文本文件中阅读和挑选特定的信息。非常感谢您的帮助

您调用没有显式实例的
indexOf
,因此java假设
this
,这里
this
属于
Marathon
类型,它没有
indexOf
(它也必须是静态的,因为
main
是静态的)


我假设您希望当前行中的
索引。为此,您必须首先使用
String line=Stats.nextLine()
获取所述行,然后使用
line.indexOf(“,”
)搜索
,“
”。错误是不言自明的,Marathon没有名为indexOf()的方法。请格式化代码,这很难阅读。如果需要,您可以从编辑器中复制粘贴,并在代码前后放置三个回标记。
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class Marathon {
public static void main (String[] args) throws FileNotFoundException{
String Time, Point, runnerNum;
File runnersLog = new File("File1");
Scanner Stats = new Scanner(runnersLog);

//while the file has another line...
while (Stats.hasNextLine()) {
//point is the distance from 0 to the first ","
Point = Stats(indexOf(0, ','));
//runnerNum is the distance from the space after the first "," until the second ","
runnerNum = Stats(indexOf(' ' , ','));
//time is the distance from the second space to the end
Time = Stats(indexOf(' '));
}
System.out.println(Point + runnerNum + Time);
Stats.close();
}
}