Java - non-static problem (Cannot use this in a static context)

 
Vista:

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
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

non-static problem (Cannot use this in a static context)

Publicado por Tom (1831 intervenciones) el 26/04/2011 17:32:19
Empieza por los tutoriales de java, es lo mejor que puedes hacer.

http://download.oracle.com/javase/tutorial/java/javaOO/classvars.html
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar