Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Need help

Thread view: 
Zero - 02 Apr 2006 09:56 GMT
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";
        }

}
Bjorn Abelli - 02 Apr 2006 10:56 GMT
"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 ^_^
Roedy Green - 02 Apr 2006 18:08 GMT
>        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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.