I am making a method in Java to read some data from a file, I want to discard those lines that are comments, that is, that start with # , for issues related to another class that I am going to pass the data to, I created an object of that class, that I pass the data when reading it from the file, the problem is that I get an error that I don't understand, related to constant references, the IDE suggests changing the attribute dato_
to static
, I don't know why. Here is the code:
public class InputTape {
MaquinaRam dato_;
public static void leeFicheroDatos(String archivo) throws FileNotFoundException, IOException {
String cadena;
FileReader f = new FileReader(archivo);
BufferedReader b = new BufferedReader(f);
while((cadena = b.readLine())!=null) {
String[] datos = cadena.split(" ");
for(int i=0;i<datos.length;i++) {
if(datos[0]!="#") {
dato_ = new MaquinaRam(datos[i]); //LINEA DEL ERROR
}
}
}
b.close();
}
}
Thank you
You have your method
public static void leeFicheroDatos(String archivo)
declared asstatic
.Methods declared as
static
have several restrictions:static
of theirclass directly.
this
orsuper
in any way.The 2nd point is the one that fails you.