Thanks for your replies and the welcome!
Fred,
just to make sure I understood you right: I would create an Arraylist that stores every line as an element and then I can go through the elemets of that Arraylist and make my calculations and whatsoever? That sounds good
. But then I have a question: why do I actually have to create another "thing" (the Arraylist)? Is it not possible to pass every single
line (which I already read in my
read_file method) to another method instead of storing all the lines to an Array? I'd like to hear about the reasons for using that Arraylist (I have never worked with that before).
Ritchie (or Campbell? ^^),
I marked my methods public because I want to access them from other classes as well. And as far as I know, this is the only way to do so.
Same with the global variables: I want to use them in other methods as well as other classes. But that's exaclty the point what my posting is about: I don't know other ways to
exchange values (e.g. my
lines or other variables) between methods. And by using a global variable I had at least access to
line in another class. Static was used because I found that on a website where they explained how to declare global variables. Until now I thought global variables were quite useful, I never came across any problems by using them (but I only do so if I can't find another option).
What do you mean by re-declaring? How would that work?
But I guess I see what you pointed out about that error:
public static String line is null until I run the read_file method. While running it changes it's value since the lines change as well. And after that i close the file and line is null again, did I get that right?
Unfortunately I'm still not sure how to pass my lines to other methods... (apart from what fred metioned, but is there really no other way? I mean, it works in my all-main-code, why not here?).
I am asking lots of questions, I know, but I
really want to understand this