This problem has been driving me nuts for the past four days as I have not for the life of me been able to figure out whether the compiler is in fact trolling me and is purposely refusing to execute my code or whether I have indeed ‘missed a trick’ and have done something wrong.
Anyways consider the following code present in one of my activity methods.
cFactory = new cFpro()
cFactory.wasCollStrC(user1.getClass().getSimpleName(),
mList.get(0).getClass().getSimpleName(), 8);
Co-operating with the following class:
public class cFpro {
private boolean inContact;
private static final String cB = "ball";
public cFpro(){
}
public boolean wasCollStrC(String s1, String s2, int d){ //cant compare arguments in if statement properly
if (d == 8) {
//if (s1.equals(s1) {
return true; //Code always skipped.
}
return false;
}
public boolean isInContact() {
return inContact;
}
}
At first I thought there was an issue with the way I was collecting the class names and other variables however I experimented by comparing simple statements which always evaluate to true.
Consider the bit in the “wasColStrC” method. When passed the following arguments the corresponding if statement ALWAYS skips the return “true” bit and DOES NOT execute the code within the statement.
cFactory.wasCollStrC(“Tree”,”Ball”,8);
With the if statement set to these condition, despite them being true, the code within their “ifs” are not executed. I have tried:
• Making both the class and methods all possible combinations of static and non static.
• Reinstalling the compiler
• Moving the "if" comparison within the method itself.
• Moving the method so that it is wihin the activitiy, i.e. this.wasCollStrC((“Tree”,”Ball”,8))
In all cases the following if statements,
public boolean wasCollStrC(String s1, String s2, int d){
if(F){
//Execute Code
return true;
}
return false;
}
With the following arguments:
cFactory.wasCollStrC(“tree”,”ball”,8);
Where 'F' is any of the following conditions, despite being reported as true by the compiler itself, ALWAYS HAS THE CODE WITHIN IT SKIPPED by said compiler for whatever reason.
if (d == 8)
if (s1.equals(s1))
if(s2.equals(“ball”)
if(s1.equals(“tree”)
if(cB.equals(Cb))
if ("b".equals("b"))
However this one works.
If(1 == 1)
I have tried my utmost and absolute best to explain the problem as clearly and as precisely as i can. Does anybody have any insight, solutions or advice as to how to fix this problem and make the code execute as it is supposed to?
Cheers!
Aucun commentaire:
Enregistrer un commentaire