non-static problem (Cannot use this in a static context)
Publicado por ricardo (1 intervención) el 26/04/2011 15:39:56
hola soy nuevo en esto de java y traigo n problemon en la empresa donde estoy dando mis practicas .
Pues resulta que tengo que validar unas formas en Java Usando JGoodies. mas o menos ya le entendi a eso. y lo que qioeren mis jefes es que adecue un codigo de una forma a otra. y resulta que me encontre con el sig. problema.
JVM me marca el sig error Cannot use this in a static context y la funcion que hice es la siguiente:
es para la validacion de las formas en JGoodies
CODIGO:------
private static ValidationResult createResult2() {
ValidationResult result = new ValidationResult();
//validate the name field
if (ValidationUtils.isEmpty(this.name.getText())) {
result.addError("The Name field can not be blank.");
}
//validate the username field
if (ValidationUtils.isEmpty(this.username.getText())) {
result.addError("The Username field can not be blank.");
} else if (!ValidationUtils.hasBoundedLength(
this.username.getText(), 6, 12)) {
result.addError(
"The Username field must be between 6 and 12 characters.");
}
//validate the phoneNumber field
String phone = this.phoneNumber.getText();
if (ValidationUtils.isEmpty(phone)) {
result.addError(
"The Phone Number field can not be blank.");
} else {
Matcher matcher = this.phonePattern.matcher(phone);
if (!matcher.matches()) {
result.addWarning(
"The phone number must be a legal number.");
}
}
return result;
}
el problema donde me marca es al usar por ejemplo el (this.) y si se lo quito no lee el objeto :(
if (ValidationUtils.isEmpty(this.name.getText())) {
Muchas Gracias por la ayuda
Pues resulta que tengo que validar unas formas en Java Usando JGoodies. mas o menos ya le entendi a eso. y lo que qioeren mis jefes es que adecue un codigo de una forma a otra. y resulta que me encontre con el sig. problema.
JVM me marca el sig error Cannot use this in a static context y la funcion que hice es la siguiente:
es para la validacion de las formas en JGoodies
CODIGO:------
private static ValidationResult createResult2() {
ValidationResult result = new ValidationResult();
//validate the name field
if (ValidationUtils.isEmpty(this.name.getText())) {
result.addError("The Name field can not be blank.");
}
//validate the username field
if (ValidationUtils.isEmpty(this.username.getText())) {
result.addError("The Username field can not be blank.");
} else if (!ValidationUtils.hasBoundedLength(
this.username.getText(), 6, 12)) {
result.addError(
"The Username field must be between 6 and 12 characters.");
}
//validate the phoneNumber field
String phone = this.phoneNumber.getText();
if (ValidationUtils.isEmpty(phone)) {
result.addError(
"The Phone Number field can not be blank.");
} else {
Matcher matcher = this.phonePattern.matcher(phone);
if (!matcher.matches()) {
result.addWarning(
"The phone number must be a legal number.");
}
}
return result;
}
el problema donde me marca es al usar por ejemplo el (this.) y si se lo quito no lee el objeto :(
if (ValidationUtils.isEmpty(this.name.getText())) {
Muchas Gracias por la ayuda
Valora esta pregunta


0