slightly off-topic
Hi, Please pardon the email handle (just something I picked to separate mailing-lists) and the (possibly, new to the mailing-list) off-topic-ness of this question... I keep hitting an obstacle while coding and I was hoping someone here could help enlighten me: A bunch of the java-standard methods return "Object" and when I try to use them, I get the following error: >> Incompatible type for declaration. Explicit cast needed to convert java.lang.Object to (whatever) In this particular instance, I've created a class which is a descendant of java.awt.Checkbox. I add an ItemListener and the listener, therefore, receives an ItemEvent. I call ItemEvent::getItem() and try to call a method that I've created for the descendant class...hence the error which would seem to imply that if I'm going to use the ItemEvent (or the java hashtable or a bunch of other stuff that I've just worked around), I can only call Object::(whatever Object methods there are) after my objects go thru the mill. I'm pretty sure whatever I'm missing is pretty basic...could anyone shed some light on this for me? Thanks, --Fred McDavid
Re: slightly off-topic
On Sat, 3 Oct 1998 02:15:03 -0500 (EST), Fred McDavid wrote:
>Hi,
>
>I keep hitting an obstacle while coding and I was hoping someone here
>could help enlighten me:
>
>A bunch of the java-standard methods return "Object" and when I try to
>use them, I get the following error:
>
> >> Incompatible type for declaration. Explicit cast needed to convert
> java.lang.Object to (whatever)
>
>In this particular instance, I've created a class which is a descendant
>of java.awt.Checkbox. I add an ItemListener and the listener, therefore,
>receives an ItemEvent. I call ItemEvent::getItem() and try to call a
>method that I've created for the descendant class...hence the error which
>would seem to imply that if I'm going to use the ItemEvent (or the java
>hashtable or a bunch of other stuff that I've just worked around), I
>can only call Object::(whatever Object methods there are) after my
>objects go thru the mill.
>
>I'm pretty sure whatever I'm missing is pretty basic...could anyone
>shed some light on this for me?
Well, are you asking why or how?
The "why" a generic "Object" type is returned from a number of methods
is because these methods are usually dealing in the abstract with any
type of object - such as the java.util.Vector class is able to store any
object type. Since all objects are subclasses of Object, the methods
are defined to take (and return) an Object so that you are now able to
use an object of any class, including those of your making.
The "how" to get arround this is much like C/C++ type casting. If,
for example, you have stored objects of class java.lang.String in a
vector, you would get them back out as follows:
java.util.Vector myVector=new java.util.Vector();
myVector.addElement("A string as an element");
String data;
data=(String) myVector.elementAt(0);
Now, note that even though a bit of code like this in C could be
dangerous since you could be taking some other object and saying
it was a String, in Java, at run time (since the compiler can not
know what type of object is in the vector) the JVM will make sure
that the object returned is a String object otherwise an exception
will be raised.
If you have an object you can also find out what its type is or
you can ask if it is an instance of a specific class without the
overhead of a try/catch of an exception while trying to typecast
the object. In most cases one actually knows that all the elements
in a vector are strings/etc so normally the cast is all that is
needed or wanted.
Michael Sinz -- Director of Research & Development, NextBus Inc.
mailto:[EMAIL PROTECTED] - http://www.nextbus.com
My place on the web ---> http://www.users.fast.net/~michael_sinz
Re: slightly off-topic
You're right, you are missing something pretty basic.
If you have a method that must return type Object or any less specific
class than the class you KNOW it to be, you use an explicit cast when
referring to the returned reference. The Java runtime will issue a
run-time error if you make an illegal cast. Here is an example (I didn't
compile this so I apologize for any lazy syntax errors).
class StringArray extends Object
{
Vector arrayOfStrings;
StringArray( String [] args )
{
int i;
for ( i = 0; i < args.length; i++ )
arrayOfStrings.addElement(args[i]);
}
String getElement( int i )
{
// LOOK HERE * the next line casts a generic Object to a String
return (String) arrayOfStrings.elementAt(i);
}
};
Douglas Toltzman
At 02:15 AM 10/3/98 -0500, you wrote:
>Hi,
>
>Please pardon the email handle (just something I picked to separate
mailing-lists) and the (possibly, new to the mailing-list) off-topic-ness
of this question...
>
>I keep hitting an obstacle while coding and I was hoping someone here
could help enlighten me:
>
>A bunch of the java-standard methods return "Object" and when I try to use
them, I get the following error:
>
> >> Incompatible type for declaration. Explicit cast needed to convert
java.lang.Object to (whatever)
>
>In this particular instance, I've created a class which is a descendant of
java.awt.Checkbox. I add an ItemListener and the listener, therefore,
receives an ItemEvent. I call ItemEvent::getItem() and try to call a
method that I've created for the descendant class...hence the error which
would seem to imply that if I'm going to use the ItemEvent (or the java
hashtable or a bunch of other stuff that I've just worked around), I can
only call Object::(whatever Object methods there are) after my objects go
thru the mill.
>
>I'm pretty sure whatever I'm missing is pretty basic...could anyone shed
some light on this for me?
>
>Thanks,
>
>--Fred McDavid
>
Windows disappearing when they appear
I am trying to use ICQ with version 1.1.6 of the JDK. Welp, I have to rename those two files libld.so.1 and libc.so.5 to elmo_blah_1 and elmo_blah_2 or else ICQ and AIM both core dump. Ok, so now it works. Well, not QUITE! Whenever i attempt to ICQ someone (by double clicking the person or selecting message from pop-up menu) the new window pops up for a millisecond and disappears. I dunno why it does this. The same thing happens with AIM. Whenever i attempt to change my password or format my screen name, it pops up the window and a millisecond later it hides the window. When i ran it from the command line (rather than through the menu item i created... am using KDE) i notice that even if I quit AIM/ICQ the window is still up and the application does not terminate. What I mean is that the main window is closed but the window that was spawned (ie: message window in ICQ or password change window in AIM) is still open. I have to ctrl-c out of it in order to kill the java process. I am wondering if anyone else had this problem, and whether there is a fix to it. If i use the standard distro version of slackware's jdk 1.1.4-v2 i do not have these problems. system: p100 os: slackware linux 3.5 kernel: 2.0.35 support for java bin as module (but not loaded) appl: ICQ 98a preview aim 1.22x aim 1.1x cheers, elmo "She wants it Now and she will not wait but she's too rough and I'm too delicate" -Smiths (Pretty Girls Make Graves)
KDE Bug w/ window creation
On Sat, 3 Oct 1998, Elmo Recio wrote: |I am trying to use ICQ with version 1.1.6 of the JDK. Welp, I have to |appl: ICQ 98a preview | aim 1.22x | aim 1.1x Hrm, i checked it out in FVWM2 and it worked fine. Seems to be a problem with KDE then. Is there anyone else out there using KDE that experienced these problems and have they done anything about these problems? I know this is off topic (i guess) email me personally then. Otherwise, i'll shout at some kde people about this ;) cheers, elmo "I was delayed, I was way-laid an emergency stop I smelt the last ten seconds of life I crashed down on the crossbar and the pain was enough to make a shy, bald buddhist reflect and plan a mass-murder" -Smiths (Stop Me If You Think You've Heard This One Before)
Re: How long will it take to port 1.1.7 ?
Andrew Burgess writes: > In mail.java-linux "Kevin B. Hendricks" <[EMAIL PROTECTED]> writes: > > >As for how long it will take to port 1.1.7? > > >This will depend on how many changes were made to the source from 1.1.6. > >Most of our diffs should apply directly but we will have to apply them by > >hand to each file to make sure that our patch does not mess up a new fix > >added by Sun. > > Do your patches go back to Sun to be integrated into their sources? They are certainly available. I believe at times we actually have sent them back as part of a bug report. When I was working there, I'd do what I could to make the changes be part of the JDK. Steve
Re: KDE Bug w/ window creation
> Elmo Recio writes: Elmo> On Sat, 3 Oct 1998, Elmo Recio wrote: Elmo> |I am trying to use ICQ with version 1.1.6 of the JDK. Welp, I have to Elmo> Elmo> |appl:ICQ 98a preview Elmo> | aim 1.22x Elmo> | aim 1.1x Elmo> Hrm, i checked it out in FVWM2 and it worked fine. Seems to Elmo> be a problem with KDE then. Is there anyone else out there Elmo> using KDE that experienced these problems and have they done Elmo> anything about these problems? It's a JDK misbehavior (actually a Sun bug), most window managers silently ignore it but with KDE windows simply disappear. We have a partial fix for this in 1.1.6v3/4a and a (hopefully) complete fix in the forthcoming 1.1.6v5. Elmo> I know this is off topic (i guess) email me personally Elmo> then. Otherwise, i'll shout at some kde people about this ;) AFAIK KDE from cvs now acts like most other window managers, i.e. the windows don't disappear anymore. Juergen -- Juergen Kreileder, Universitaet Dortmund, Lehrstuhl Informatik V Baroper Strasse 301, D-44221 Dortmund, Germany Phone: ++49 231/755-5806, Fax: ++49 231/755-5802
Re: Dynamic modification of CLASSPATH
could you not get an instance of runtime and execute
'export CLASSPATH=/some/new/classpath' or set env, depending
what shell your using. Then again, that is not very platfom independant
now is it?Well, it would work.
__
Kenny Freeman <[EMAIL PROTECTED]>
"a population that gives up its freedoms in the name of order will
ultimately end up losing both."
On Fri, 2 Oct 1998 [EMAIL PROTECTED] wrote:
> You can also get the classpath from SystemProperty( "java.classpath" )
> or something like that.
>
> Then use you write a PathnameResolve sth that search for the classes
> by looking at each of the separated directory. You could use
> the StringTokenizer(":") to get each directory. Loop through all
> directories and try to see if there is File called xxx.class or
> whatever.
>
> Or maybe there's a method in ClassLoader which accepts a new
> (augmented) classpath.
>
> Pete
>
> __ Reply Separator _
> Subject: Re: Dynamic modification of CLASSPATH
> Author: gaolei ([EMAIL PROTECTED]) at lon-mime
> Date:02/10/98 08:59
>
>
> You could write your own class loader.
>
> Domingo Pinya wrote:
>
> > Hi:
> >
> >There is any way to change the value of CLASSPATH dynamicaly, that is,
> > how I can include a new directory into CLASSPATH after my program is
> > runnning, to instantiate a class that is inside it?
> >
> > Thanks.
> >
>
>
>
multicast via slip
Hi, Does anyone know whether linux java allow multicast via slip? Currently, I am running jdk 1.1.6v1 and have a modem (28.8k) running slip. TCP/IP runs ok but it gave me core dump when I tried to join multicast group: java.net.SocketException: Cannot assign requested address at java.net.MulticastSocket.joinGroup(MulticastSocket.java:153) at Client.joinMulticast(Client.java:29) at Client.run(Client.java:39) The code runs fine on a SUN solaris machine and on a linux box with ethernet connection. I have fixed ip address although I am running slip over modem. Thanks. --- Gwobaw ([EMAIL PROTECTED]) 3115 EECS, (313) 647-3780
Re: slightly off-topic
Thanks guys...I figured it was something pretty basic...the books I have mention 'explicit casting', but didn't show any examples. Thanks again, --Fred
Re: multicast via slip
On Sat, 3 Oct 1998, Gwobaw A. Wu wrote: > Hi, > > Does anyone know whether linux java allow multicast via slip? > Currently, I am running jdk 1.1.6v1 and have a modem (28.8k) running slip. > TCP/IP runs ok but it gave me core dump when I tried to join multicast > group: >java.net.SocketException: Cannot assign requested address > at java.net.MulticastSocket.joinGroup(MulticastSocket.java:153) > at Client.joinMulticast(Client.java:29) > at Client.run(Client.java:39) > > The code runs fine on a SUN solaris machine and on a linux box with > ethernet connection. > I have fixed ip address although I am running slip over modem. > > Thanks. > --- Gwobaw ([EMAIL PROTECTED]) > 3115 EECS, (313) 647-3780 > I'm not sure you can use multicast at all over slip. If you have access to another computer with multicast-capable computer you could try mTunnel, an application for tunneling multicast over an unicast connection: http://www.cdt.luth.se/~peppar/progs/mTunnel/ (mTunnel is an Java application written by my co-worker Peter Parnes.) //Roland Parviainen
Install Problems!!
Hello all, I'm new to Java for Linux, and am having some problems getting the JDK1.1.6v4a installed on my Linux Redhat 5.1 system. It seams that java wants me so set some library path variable, but I do not know which one. I downloaded the jdk1.1.6v4a for glibc and untarred it just like the instructions said. I then set the PATH and CLASSPATH variable just like I was told to do. After that I just tried to run the appletviewer with a demo, but it says that "no library path set". This also occurs when I just try to use javac and .java. Could someone please tell me what I am doing wrong? I would be very greatful. Thanks, Lonnie..
Re: Install Problems!!
Lonnie Cumberland wrote: > I'm new to Java for Linux, and am having some problems getting the > JDK1.1.6v4a installed on my Linux Redhat 5.1 system. It seams that java > wants me so set some library path variable, but I do not know which one. > > I downloaded the jdk1.1.6v4a for glibc and untarred it just like the > instructions said. I then set the PATH and CLASSPATH variable just like > I was told to do. After that I just tried to run the appletviewer with > a demo, but it says that "no library path set". This also occurs when I > just try to use javac and .java. Don't set CLASSPATH. Set PATH to include just the bin directory. e.g. I unzip the file to /usr/local/jdk116a, make a symbolic link with cd /usr/local; ln -s jdk116a jdk and put /usr/local/jdk/bin in my PATH. (That way I can switch between JDK's by changing a single symlink.) It may help to uninstall older JRE's on your machine, too. - Dan
Problem found!!
Thanks all, My install problem was corrected when I took out kaffe. I uses rpm -e kaffe and everything was fine. Thanks all, Now I can get to work on developing some mobile-agent stuff Lonnie.
