开发者

The method replaceVariables(String) is undefined for the type

开发者 https://www.devze.com 2023-01-01 16:23 出处:网络
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?

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开发者_如何学Go("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.


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).


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

  • Java String.equals versus ==

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

  • String vs StringBuilder
  • Why to use StringBuffer in Java instead of the string concatenation operator
  • StringBuilder and StringBuffer in Java
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号