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 2 of 2

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
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 5
    Last Post: December 9th, 2012, 02:25 PM
  2. 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, 02:23 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 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, 01:22 AM