----- Original Message -----
From: "Mike Abney" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 28, 2001 10:23 AM
Subject: Re: Static Reference Issue


> No, but I'm guessing that UserBean is the name of your class and not an
> instance of the class. Your code should read more like this:
>
>   UserBean aBean;
>
>   // ... something that initializes aBean ...
>
>   try {
>     // ...
>     aBean.setLastAccess( rs.getString( "lastaccess" ));
>     // ...
>   }
>
> The class name being before the dot (in your original code) makes the
> "static context" and your "setLastAccess" method was definitely not
defined
> as static.
>
>
>
> ~Mike
>
> ----- Original Message -----
> From: "Mark Galbreath" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, December 28, 2001 9:13 AM
> Subject: Static Reference Issue
>
>
> > I know I've run across this before, but can't remember the circumstance.
> > When I attempt to set a JavaBean property from a servlet as so:
> >
> > try {
> >     ...
> >     UserBean.setLastAccess( rs.getString( "lastaccess"));
> >     ...
> > }
> >
> > with the bean method as:
> >
> > public void setLastAccess( String lastaccess) {
> >     this.lastaccess = lastaccess;
> > }
> >
> > I get a compile-time error:
> >
> > "non-static method setLastAccess( java.lang.String) cannot be accessed
> from
> > a static context."
> >
> > Is a <try> block considered a static context?
> >
> > ~Mark
>[...]

yes, I test it with J2SE1.3, when I access a instance-method by the
class-name directly,
the compiler's output is:
 "non-static method m2( ) cannot be referenced from a static context"
 "non-static method m2( ) cannot be referenced from a static context"

when compiler says "static context",  it means Class-Name(Class-Name is a
static context),
not try/catch/finally block.


public class MyTest {
    public void m0(){
        MyUtility.m2();
    }

    public static void m1(){
        MyUtility.m2();
    }
}

class MyUtility {
    public void m2(){}
}


Happy new year! :-)
Bo
Dec.28, 2001

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to