Re: Problem creating an NSButton subclass in Java
Re: Problem creating an NSButton subclass in Java
- Subject: Re: Problem creating an NSButton subclass in Java
- From: Tom Sutcliffe <email@hidden>
- Date: Mon, 4 Aug 2003 18:38:31 +0100
I tried this and you're absolutely right, the nib stuff requires the
NSCoder constructor and not a no-args one. Which is odd as I read this
article ages ago ranting about the java bridge which insisted on having
to provide no-args constructors, and that's where I'd always assumed
the problem lay. Gives me a whole new appreciation of the 'the init
method is nothing special' approach of objective-c.
Incidentally, and for the archives' sake, if you're still using
pre-10.2 (non-keyed archives) nibs the error will be even harder to
decipher:
AppKitJava: uncaught exception NSArchiverArchiveInconsistency (*** file
inconsistency: read '@', expecting 'C')
Also the exact format of the constructor is
protected MyButton(NSCoder decoder, long token) {
super(decoder, token);
// Read in any extra instance variables you've defined
}
and you don't have to define encodeWithCoder, whatever the NSCoding
protocol says, unless you have some other instance variables to encode
of course.
Tom
On Saturday, August 2, 2003, at 09:24 pm, Chris Boot wrote:
Hi,
I think the problem actually depends on having an NSCoder constructor,
as such:
public DroppableButtonClass(NSCoder coder) {
super(coder);
}
Hope this helps (and if I'm wrong somebody shout at me)
- Chris
On Saturday, Aug 2, 2003, at 20:51 Europe/London, Chris Backas wrote:
I'm trying to subclass an NSButton in my program with a Java class,
so
I've picked NSButton in IB, subclassed it, clicked the button in my
form, set the custom class property to my new subclass, and created
the file
for my new class. (Did I miss anything?)
For whatever reason, my program won't run when my subclass is set at
the button's custom class. I get this cryptic console error:
jobjc_jvm_newObject(): constructor with signature
(Ljava/io/InputStream;)V on class java/io/ObjectInputStream failed
(should morph the java exception)
I don't know what this is referring to, as I don't use the
java.io.ObjectInputStream class. Am I missing a step in my above
procedure? Thanks for any help.
You've run into a problem when subclassing any object that goes
through
the java bridge. Basically you have to define a no-arguments
constructor in your subclass. It's to do with how the NSArchiving of
stuff in IB works, if you don't define this method the runtime can't
instantiate your class.
public class MyButton extends NSButton {
public MyButton() {
super(); // Need to call this
// Otherwise you can leave this blank.
}
}
Happy subclassing,
Tom
Hi Tom,
Thanks for replying. This actually occurred to me, so I have this
for my class so far:
import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
import java.io.*;
public class DropableButtonClass extends NSButton
{
public DropableButtonClass()
{
super();
};
public DropableButtonClass(NSRect frame)
{
super(frame);
};
}
It doesn't make a difference in the error though. I'd actually
created these constructors just to mimic the ones that NSButton had
in its documentation. Any other ideas? I'm stumped =)
Chris Backas
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
Chris Boot
email@hidden
http://www.bootc.net/
"Science is what we understand well enough to explain to a computer.
Art is everything else we do." - Donald Knuth
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.