errors within constructor  
Author Message
El Durango





PostPosted: 2004-8-6 16:33:00 Top

java-programmer, errors within constructor Hi I am working on a project and I am getting an error that I do not
understand.

I have the part of the code below along with the line that gives error.

From the exception message I can assume that the object I pass to the
HashMap is a null object but in the code below I create a new object and
initialize it.

I appreciate any advice.

// group IP address
private static final String MULTGRP = "225.4.5.6";

private InetAddress group = InetAddress.getByName(MULTGRP);
private static HashMap mapGroupSocket = null;
// constructor
public IRCServer()throws IOException{
// create sockets for all groups.
MulticastSocket mcastCsci5431 = new MulticastSocket(CSCI5431_PORT);
mcastCsci5431.joinGroup(group);
// other code (not relevant)
mapGroupSocket.put(CSCI5431, mcastCsci5431); <---- exception
thrown.
}




Error:

Exception in thread "main" java.lang.NullPointerException
at IRCServer.<init>(IRCServer.java:91)
at IRCServer.main(IRCServer.java:105)



 
Vincent Cantin





PostPosted: 2004-8-6 16:46:00 Top

java-programmer >> errors within constructor > From the exception message I can assume that the object I pass to the
> HashMap is a null object but in the code below I create a new object and
> initialize it.

From the error essage, I assume that it is the mapGroupSocket which is null.


 
Pimousse





PostPosted: 2004-8-6 17:01:00 Top

java-programmer >> errors within constructor Vincent Cantin a 閏rit :

>>From the exception message I can assume that the object I pass to the
>>HashMap is a null object but in the code below I create a new object and
>>initialize it.
>
>
> From the error essage, I assume that it is the mapGroupSocket which is null.
>
>

Same conclusion. Indeed, you declared mapGroupSocket = null, and nowhere
I saw sth to "instanciate" mapGroupSocket.

And I do not understand why your HashMap mapGroupSocket is declared
static ...

@++
Pimousse
 
 
Andrew Thompson





PostPosted: 2004-8-6 17:57:00 Top

java-programmer >> errors within constructor On Fri, 06 Aug 2004 08:32:38 GMT, El Durango wrote:

> Hi I am working on a project and I am getting an error that I do not
> understand.

You are also working on a Usenet that
you apparently do not understand.

Please see the answers* you have already received
on c.l.j.help, and please do not multi-post.
<http://www.physci.org/codes/javafaq.jsp#xpost>

* Yes, Gordon's answer echoed the
suspicions of Vincent and Pimousse..

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
 
El Durango





PostPosted: 2004-8-7 13:34:00 Top

java-programmer >> errors within constructor
"Andrew Thompson" <email***@***.com> wrote in message
news:email***@***.com...
> On Fri, 06 Aug 2004 08:32:38 GMT, El Durango wrote:
>
> > Hi I am working on a project and I am getting an error that I do not
> > understand.
>
> You are also working on a Usenet that
> you apparently do not understand.
>
> Please see the answers* you have already received
> on c.l.j.help, and please do not multi-post.
> <http://www.physci.org/codes/javafaq.jsp#xpost>
>
> * Yes, Gordon's answer echoed the
> suspicions of Vincent and Pimousse..
>
> --
> Andrew Thompson
> http://www.PhySci.org/ Open-source software suite
> http://www.PhySci.org/codes/ Web & IT Help
> http://www.1point1C.org/ Science & Technology

Sorry about the multi-post.
Thanks to all for pointing out what I overlooked, it was a silly mistake.