"daniel.w.gelder" <> wrote:
[I don't have much knowledge to offer. Instead, let me
play potted plant here and see if it helps.]
> Apparently I have to define my own constructor,
> even if it doesn't do anything.
That shouldn't be the case, if you don't explicitly
define a parameterless void constructor, the system
creates a default one for you which calls super()
and returns. In fact, creating such a constructor
and making it private so it can't be invoked is one
frequently seen trick to prevent the system from
supplying such a default constructor unbeknownst to
you and having it invoked where you had no such
intention.
> I seem to need to define an <init> method with signature
> "()V", otherwise myClass.newInstance() throws InstantiationException.
1) Are those angle brackets a literal part of the name "<init>"?
Is that some template parameter naming, or what?
2) What does the "V" in "()V" mean? "Void return?"
> Anyway, there's nothing in <init> except a return statement. So I get
> this exception:
> java.lang.VerifyError: (class: Dan, method: <init> signature: ()V)
> Constructor must call super() or this()
Is that a compile time error, or a run time error? It looks
like a runtime invocation of MyClass.init() has encountered
a problem with a constructor for MyClass being missing, but
as noted above, one should be created (and then invoked) by
default if you don't prevent that happening.
> So apparently I have to call Object.<init>() too. Makes sense, but I
> thought you could never call <init> yourself. Is there a trick here?
I'm still confused by those angle brackets, but it isn't "init"
that you are being told to call, you are being told, at a default
invocation of MyClass.init() at startup time, that you haven't
yet instantiated an object from MyClass, thus there is no object
whose instance (as opposed to static) method init() can be invoked.
A common pattern is to have your main routine inherit from
applet, to instance applet in main(...), then to invoke init()
from that instance.
class MyClass extends applet
{
private static MyClass mc = null;
public MyClass() // constructor
{
super();
}
void main(...) // must exist in some class of your app
{
mc = new MyClass();
mc.init(); // yes, you _can_ call init() yourself
// ... do more stuff
}
void init()
{
// initialize stuff for instance object mc of MyClass.
}
}
Or something vaguely like that. Until I figure out how
to boot Debian Linux using grub on and from an external
drive (to leave the internal drive's MS-Windows garbage
unmolested) on my replacement laptop, I'm temporarily
out of the Java business.
FWIW
xanthian.
--
Posted via Mailgate.ORG Server -
http://www.Mailgate.ORG