1

I get this message for as many times as I have used replaceVariables in my code. I have added the referenced libraries, but I don't know what else to do. Can someone please help me?

Update: This is the code:

   int k = 0;
for(Xml reg_is:fetchsite.child("site").child("regexps").children("reg"))    
{
if(reg_is.string("name").contains("unique")){


if(reg_is.child("start").content()=="")
    error += "\tNo prefix reg.exp. given.\n";

  else
prefix = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("start").content()));                       

if(reg_is.child("end").content()=="")
    error += "\tNo suffix reg.exp. given.\n";
 else
suffix = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("end").content()));

}
else{
  poleis[k][0]= HtmlMethods.removeBreaks(reg_is.string("name"));
  poleis[k][1] = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("start").content()));//ιδια δομη για ολες τις πολεις
  poleis[k][2] = HtmlMethods.removeBreaks(replaceVariables(reg_is.child("end").content()));
  k++;
 }
}

In this part I use my XML in order to find the data from a HTML page that I want.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
kate
  • 37
  • 2
  • 6

2 Answers2

1

So, replaceVariables needs to be either a method which is declared in the same class, or it needs to be a static method which is imported using import static. Since it seems to be a method of the HtmlMethods class, my bet is that adding the following line to the imports should fix the problem:

import static com.example.HtmlMethods.*;

You only need to substitute com.example with the actual package name. Another way is to use HtmlMethods.replaceVariables(x) in your code instead.


That said, doing a string == "" is not the way to determine if the string equals an empty string. You should use either

if (string.equals("")) {}

or

if (string.length() == 0) {}

or

if (string.isEmpty()) {}

instead. Be aware that string is supposed to be non-null here, else you need to add a string != null as well or to use "".equals(string).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • i did it and it doesn't accept this oimport the excact message is"the import HtmlMethods cannot be resolved"and off the record i have created a class HtmlMethods so i don't know why this message is coming up :( – kate May 28 '10 at 21:39
  • Is it been placed in a package? You should do that, else you cannot import it in classes sitting in a package. – BalusC May 28 '10 at 21:41
  • i don't know why this think is connected with replaceVariables i have the same code in another project and it isn't wrong :( – kate May 28 '10 at 21:43
  • +1; feel free to transplant anything from my answer too. I've given up on this one. – polygenelubricants May 28 '10 at 21:44
  • @kate: apparently an older version of the `HtmlMethods` class missing this method is been placed in the classpath? Do you use an IDE? Ctrl+Click the `HtmlMethods` class and explore it. – BalusC May 28 '10 at 21:45
  • ok thanks alot i will try everything i hope that i will find an answer thanks for your time and your patience – kate May 28 '10 at 21:55
0

On == on reference types

someString == "" is almost always wrong. == is a reference identity comparison. If you want value comparison, use equals. In this particular case, you can use either someString.length() == 0 or someString.isEmpty()

Related questions

On += on String

Be aware that this performs quite horribly (quadratic) with really long strings. If you're doing this in a any sizable loop, you'd definitely see the effect. It'd be better to use a StringBuilder.

Related questions

Community
  • 1
  • 1
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623