Java 名为“的方法没有适用的重载”;rf";在“类型”中找到;mp3“U组织者”;
我不知道该怎么办,因为我确保了方法没有重复的名称,我试图搜索问题,但似乎每个人的问题都与我的不同,尽管输出显示类似的东西 代码: 问题在于:Java 名为“的方法没有适用的重载”;rf";在“类型”中找到;mp3“U组织者”;,java,Java,我不知道该怎么办,因为我确保了方法没有重复的名称,我试图搜索问题,但似乎每个人的问题都与我的不同,尽管输出显示类似的东西 代码: 问题在于: public static void rf (String[] songname, String[] songpath, String[] artist, String[] genre, int[] count, String file){ //... } 您有六个参数,在方法实现中,int cuunt[]是一个数组 songname [count
public static void rf (String[] songname, String[] songpath, String[] artist, String[] genre, int[] count, String file){
//...
}
您有六个参数,在方法实现中,int cuunt[]
是一个数组
songname [count [0]] = line;
songpath [count [0]] = reader.readLine ();
artist [count [0]] = reader.readLine ();
genre [count [0]] = reader.readLine ();
count [0]++;
但是当调用该方法时,pass六个参数但是作为变量计算:
rf (songname, songpath, artist, genre, count, file);
search (songname, songpath, artist, genre, count, file);
要解决此问题,您需要重载方法,将count作为变量传递,以与方法实现相匹配。如果只想作为变量传递,则更改为数组。如下所示:
//method count array
public static void rf (String[] songname, String[] songpath, String[] artist, String[] genre, int[] count, String file) throws FileNotFoundException, IOException
{
BufferedReader reader = new BufferedReader (new FileReader (file));
String temp, line = null;
while ((line = reader.readLine ()) != null)
{
songname [count [0]] = line;
songpath [count [0]] = reader.readLine ();
artist [count [0]] = reader.readLine ();
genre [count [0]] = reader.readLine ();
count [0]++;
}
reader.close ();
}
//overloaded six parameter method
//without count array. count variable
public static void rf (String[] songname, String[] songpath, String[] genre, int count, String file) throws FileNotFoundException, IOException
{
BufferedReader reader = new BufferedReader (new FileReader (file));
String temp, line = null;
while ((line = reader.readLine ()) != null)
{
songname [count [0]] = line;
songpath [count [0]] = reader.readLine ();
artist [count [0]] = reader.readLine (); - remove this line
genre [count] = reader.readLine ();//change this too, genre [count[0]]
count++;//since this is not a array change to count[0]++.
}
reader.close ();
}
您还需要重载search()
与调用函数不匹配(文件
参数不在实现中):
更新:
这些也必须根据您的上述实现进行更改
songname [count [0]] = line;
songpath [count [0]] = reader.readLine ();
artist [count [0]] = reader.readLine ();
genre [count [0]] = reader.readLine ();
count [0]++;
我认为您可以将count
参数作为数组传递给rf()
和search()
,而不是更改所有这些参数。否则,您需要更改整个程序。这取决于你想办法做到这一点
阅读更多关于
search (songname, songpath, artist, genre, count, file);
songname [count [0]] = line;
songpath [count [0]] = reader.readLine ();
artist [count [0]] = reader.readLine ();
genre [count [0]] = reader.readLine ();
count [0]++;