Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Re: Error Message: Exception in thread "main" java.lang.NullPointerException etc.

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error Message: Exception in thread "main" java.lang.NullPointerException etc.

    help me to solve this error: -

    import java.io.IOException;

    import java.net.InetAddress;

    import java.net.NetworkInterface;

    import java.net.URLConnection;
    import java.net.UnknownHostException;
    import java.net.*;


    public class IsReachable
    {


    public static void main(final String[] args) throws IOException
    {

    InetAddress host;
    try
    {


    for (int i = 1; i < 255; i++)
    {

    host = InetAddress.getByName("192.168.6." + i);

    NetworkInterface network = NetworkInterface.getByInetAddress(host);

    byte[] mac = new byte[100];
    mac=network.getHardwareAddress();


    StringBuilder sb = new StringBuilder();


    for (int j = 0; j < mac.length; j++)
    {

    sb.append(String.format("%02X%s", mac[j], (j < mac.length - 1) ? "-" : ""));

    }


    if (host.isReachable(10000))
    {

    System.out.println("Connected " + host + " " + sb.toString());

    }
    else
    {

    System.out.println("Failed " + host);

    }

    }

    }
    catch (UnknownHostException e) {


    e.printStackTrace();


    }
    catch (SocketException e) {


    e.printStackTrace();

    }

    }

    }

    ____________Output______________


    C:\Program Files\Java\jdk1.6.0_05\bin>javac IsReachable.java

    C:\Program Files\Java\jdk1.6.0_05\bin>java IsReachable
    Exception in thread "main" java.lang.NullPointerException
    at IsReachable.main(IsReachable.java:32)

    thank u


  2. #2
    Administrator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,848
    Thanks
    64
    Thanked 2,645 Times in 2,615 Posts

    Default Re: Error Message: Exception in thread "main" java.lang.NullPointerException etc.

    Exception in thread "main" java.lang.NullPointerException
    at IsReachable.main(IsReachable.java:32)
    Look at line 32 in the your source and see what variable is null. Then backtrack in the code to see why that variable does not have a valid value.
    If you can not tell which variable it is, add a println just before line 32 and print out the values of all the varibles on that line.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default parjdngzz rdtsclmvc mgworpipj mlmvzmmuf inovgffpo

    Good day! I know this is kinda off topic but I'd figured I'd ask. Would you be interested in trading links or maybe guest writing a blog article or vice-versa? My website addresses a lot of the same topics as yours and I believe we could greatly benefit from each other. If you happen to be interested feel free to shoot me an e-mail. I look forward to hearing from you! Excellent blog by the way click to read more!


    read link:
    check this
    Homepage
    blog here
    resources
    helpful hints

Similar Threads

  1. Replies: 4
    Last Post: December 23rd, 2012, 09:56 AM
  2. Replies: 5
    Last Post: December 9th, 2012, 02:25 PM
  3. Exception in thread "main" java.lang.NullPointerException problem.......
    By Adam802 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2012, 03:23 AM
  4. [SOLVED] Error Message: Exception in thread "main" java.lang.NullPointerException etc.
    By coffecupcake in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 15th, 2011, 09:34 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 02:22 AM