I am a new guy here and have some problem I can't handle. I just write
a small class that hava a inner class. When the program running to the
line that I marked with **, it will call a exception like this: at
basicDomainNameLookUp.WellKnownPorts.<init>(WellKnownPorts.java:27).
Could somebody help me sovle this problem T_T, I really can't handle
it.Thanks.
public class WellKnownPorts
{
/**
* @param args
*/
PortElement[] EKPs ;
protected class PortElement
{
protected int portNum;
protected String serviceName;
protected String serviceAlias;
protected void ProtElement ( int inputPortNum , String
inputServiceName , String inputServiceAlias )
{
portNum = inputPortNum;
serviceName = inputServiceName;
serviceAlias = inputServiceAlias;
}
}
//Constractor
public WellKnownPorts ()
{
EKPs = new PortElement[14];
** EKPs[0].portNum = 7; **
EKPs[0].serviceName = "echo";
EKPs[0].serviceAlias = "echo";
EKPs[1].portNum = 13;
EKPs[1].serviceName = "DayTime";
EKPs[1].serviceAlias = "DayTime";
EKPs[2].portNum = 20;
EKPs[2].serviceName = "File Transfer Protocol";
EKPs[2].serviceAlias = "FTP";
EKPs[3].portNum = 21;
EKPs[3].serviceName = "File Transfer Protocol";
EKPs[3].serviceAlias = "FTP";
EKPs[4].portNum = 25;
EKPs[4].serviceName = "Simple Mail Transfer Protocol";
EKPs[4].serviceAlias = "SMTP";
EKPs[5].portNum = 37;
EKPs[5].serviceName = "Time";
EKPs[5].serviceAlias = "Time";
EKPs[6].portNum = 80;
EKPs[6].serviceName = "HyperText Transfer Protocol";
EKPs[6].serviceAlias = "HTTP";
EKPs[7].portNum = 53;
EKPs[7].serviceName = "Domain Name Service";
EKPs[7].serviceAlias = "DNS";
EKPs[8].portNum = 110;
EKPs[8].serviceName = "Post Office Protocol version 3";
EKPs[8].serviceAlias = "POP3";
EKPs[9].portNum = 123;
EKPs[9].serviceName = "Network Time Protocol ";
EKPs[9].serviceAlias = "NTP";
EKPs[10].portNum = 519;
EKPs[10].serviceName = "utime";
EKPs[10].serviceAlias = "utime";
EKPs[11].portNum = 525;
EKPs[11].serviceName = "timed timeserver";
EKPs[11].serviceAlias = "timed timeserver";
EKPs[12].portNum = 580;
EKPs[12].serviceName = "Simple Network Time Protocol heartbeat";
EKPs[12].serviceAlias = "SNTP";
EKPs[13].portNum = 8889;
EKPs[13].serviceName = "dbAnywhere";
EKPs[13].serviceAlias = "dbAnywhere";
}
}
"Zero" wrote...
>I am a new guy here and have some problem I can't handle.
For newbie questions, a better place is comp.lang.java.help
> When the program running to the
> line that I marked with **, it will call a exception like this: at
> basicDomainNameLookUp.WellKnownPorts.<init>(WellKnownPorts.java:27).
You don't write what the actual error is. It helps us to help you if you
provide all information about such errors.
In this case I guess it's a simple null pointer exception...
> Could somebody help me sovle this problem T_T, I really can't handle
> it.Thanks.
[snip]
Here you create an array of PortElements...
> EKPs = new PortElement[14];
...but you never instantiate any! That means that, there are 14
null-references in your aray, but none actually existing. You can't change
an attribute of an instance until you've instantiated it.
> EKPs[0].portNum = 7; **
> EKPs[0].serviceName = "echo";
> EKPs[0].serviceAlias = "echo";
You have a constructor in that class, which should simplify it, something
like this maybe...
EKPs[0] = new ProtElement ( 7, "echo", "echo" );
...etc...
// Bjorn A
Zero - 02 Apr 2006 14:14 GMT
Thank U evry much!!!
It's working properly now ^_^
> EKPs = new PortElement[14];
>** EKPs[0].portNum = 7; **
see http://mindprod.com/jgloss/gotchas.html#ARRAY

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.