问题描述:

I can't figure out what exactly is wrong. This is what i get when i compile this program:

cannot find symbol method kuce(java.util.List<java.lang.String>,java.lang.String[]).

If i change this row:

System.out.print(mauka.kuce(mauka,temp));

to

System.out.print(mauka.kuce(mauka,temp[]));

then i get this:

'.class' expected

Here is the full code

import java.io.*;

import java.util.*;

class metodes

{

String p="";

public String kuce(List x, String c[]) {

for (int v=0; v < x.size(); v++) p = p +c[v] ;

return p;

}

}

public class ShowFile

{

public static void main(String args[]) throws IOException

{

int i;

FileInputStream fin;

try {

fin = new FileInputStream(args[0]);

} catch(FileNotFoundException e) {

System.out.println(" Fails nav atrasts");

return;

} catch(ArrayIndexOutOfBoundsException e) {

System.out.println(" Ievadiet: ShowFile faila_vards");

return;

}

StringBuffer ab = new StringBuffer();

String a="";

String temp[];

do {

i = fin.read();

if (i!=-1) a= a + ((char) i);

} while(i != -1);

a = a.replace("\r\n", " ");

temp = a.split("\\.");

String h = ".";

for (int o = 0; o < temp.length; o++) {temp[o] = temp[o] + h;}

List<String> mauka = Arrays.asList(temp);

System.out.print(mauka.kuce(mauka,temp));

fin.close();

}

}

网友答案:

kuce() is a method on the class metodes. You're trying to call it on class List<String>, as that's what the variable mauka is declared as. You need to make an instance of metodes and then you can call kuce() on that.

网友答案:

The problem reported by compiler means that it is unable to find kuce() with the List interface of Collections.

kuce() method has been defined in metodes class and only can be used with the objects of metode . You are trying to call kuce() on List interface .

could you please change your code to create and object of metodes and then call kuce() on it.

相关阅读:
Top