problems with static variables and methods

Ok, so I have a loop in my constructor that sets 5 variables with unique Strings every time it loops. I need to run those 5 variables through a couple of methods which decide whether to print the variables to a txt file or not.

My problem is that the loop is apparently a static context, and I can't make the methods static. Is there any way to make this work short of taking the code out of the method and putting it directly in the loop?

Thanks.

[468 byte] By [snoboardera] at [2007-11-27 4:36:24]
# 1
That may make sense if you post some code.
Hippolytea at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...
# 2

ok, well I'll try to cut it down some

try {

fileFound = true;

BufferedWriter out = new BufferedWriter(new FileWriter("Error Logs\\" + namefile + " error log.txt"));

// open the file and read the lines

br = new BufferedReader(new FileReader(newFile));

lines = new BufferedReader(new FileReader(newFile));

int length = 0;

while(lines.readLine() != null){

length++;

}

String readline = "";

String id = "";

String client = "";

String description = "";

Boolean entry = false;

String taskCode = "";

String activityCode = "";

readline = br.readLine();

int line = 0;

ArrayList<String> variables = new ArrayList<String>();

while(line < length){

readline = br.readLine();

if(readline.contains("</TABLE>") || readline.contains("/HTML"))

break;

if(readline.contains("#000000\">")){

int i = 0;

variables.clear();

while(i<5){

int tagIndex = readline.indexOf("#000000\">") + 1;

readline = readline.substring(tagIndex);

variables.add(readline.substring(8, readline.indexOf("<")));

i++;

}

i = 0;

while(i<5){

String variable = variables.get(i).toString();

if(variable.contains("L") || variable.contains("E")){

if(variable.length() == 4){

taskCode = variable;

}

}

if(variable.contains("A") && variable.length() == 4)

activityCode = variable;

if(variable.contains("-"))

id = variable;

if(variable.contains(",")){

int j = 0;

int spaces = 0;

while(j < variable.length()){

if(variable.charAt(j) == ' '){

spaces++;

j++;

}

else

j++;

}

if(spaces >= 3)

description = variable;

else

client = variable;

}

i++;

}

}

//The previous code provides the client, description, taskCode, activityCode, and id variables, now it checks them for accuracy

RunMethod.aABAChecker(activityCode, taskCode, description);

RunMethod.anoABAChecker(activityCode, taskCode, description);

line++;

}

}

catch (IOException e) {

return;

}

public void eABAChecker (String ecode, String eDescription) throws IOException{

BufferedReader lines = new BufferedReader(new FileReader("Client Filters\\ABA Codes\\" + ecode + ".txt"));

BufferedReader ecodereader = new BufferedReader(new FileReader("Client Filters\\ABA Codes\\" + ecode + ".txt"));

int linenumber = 0;

while(lines.readLine() != null){

linenumber++;

}

boolean contains = false;

for(int l = 0; l < linenumber; l++){

if(eDescription.contains(ecodereader.readLine()))

contains = true;

}

if(contains == false)

eError = ecode;

}

public void enoABAChecker (String ecode, String eDescription) throws IOException{

BufferedReader lines = new BufferedReader(new FileReader("Client Filters\\ABA Codes\\" + ecode + ".txt"));

BufferedReader ecodereader = new BufferedReader(new FileReader("Client Filters\\ABA Codes\\" + ecode + ".txt"));

int linenumber = 0;

while(lines.readLine() != null){

linenumber++;

}

boolean contains = false;

for(int l = 0; l < linenumber; l++){

if(eDescription.contains(ecodereader.readLine()))

eError = ecode;

}

}

my constructor is RunMethod

The error was when I tried to call the methods. can't call nonstatic method in static context

snoboardera at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...
# 3
Do the methods in question rely on some particular state? If not, why are they not static?
paulcwa at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...
# 4
> my constructor is RunMethodThat makes no sense.
Hippolytea at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...
# 5
The methods can't be static because they rely on nonstatic variables in the constructor. I forgot to include them here, but it was basically justString lerror = "";String aerror = "";
snoboardera at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...
# 6
I apologize, I meant the class was RunMethod, because that's how I call the methods, RunMethod.aABAChecker(.....
snoboardera at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...
# 7
If the methods rely on object state, then the method that calls them relies on object state, and therefore, that method -- the static one -- shouldn't be static.
paulcwa at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...
# 8
i got it
snoboardera at 2007-7-12 9:46:34 > top of Java-index,Java Essentials,New To Java...