title: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
body: <p>I am trying to get the host address by passing host name. But while running my code, I get the exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
      at socketprogram_client.SocketProgram_Client.main(SocketProgram_Client.java:16)
  Java Result: 1
  </code></pre>
  
  <p>Can anyone please tell me why I am getting this error?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package socketprogram_client;
  
  import java.io.*;
  import java.net.*;
  
  public class SocketProgram_Client 
  {
      public static void main ( String args[] ) throws IOException 
      {
          String host_name = args[0];
  
          try
          {
              InetAddress my_ipaddr = InetAddress.getByName(host_name);
              System.out.println("Resolved to IP address: " + my_ipaddr.getHostAddress());
          }
          catch ( UnknownHostException e )
          {
              System.out.println("Could not find IP address for: " + host_name);
          }
      }
  }
  </code></pre>