• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Can't get where to improve showing error  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here in client it is showing error in line" Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
       at GreetingClient.main(GreetingClient.java:8)"

In server:- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
       at GreetingClient.main(GreetingClient.java:8)

java files are attached..
Please guide me..
 
Ranch Hand
Posts: 90
Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Setul,

Welcome to the Ranch!

How did you include the attachments? Can you include the code in the post?
 
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
       at GreetingClient.main(GreetingClient.java:8)"


That error says the code at line 8 in GreetingClient used an index of 0 in an empty array.  The code should check that the array has at least one element before trying to access its first element.
Use the array's length attribute to test the size of the array.  
theArray.length returns the number of elements in the array
 
Hetul Sheth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hetul Sheth wrote:Here in client it is showing error in line" Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
       at GreetingClient.main(GreetingClient.java:8)"

In server:-Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
       at GreetingServer.main(GreetingServer.java:42)

java files are attached..
Please guide me..



CLIENT CODE




SERVER CODE

 
Hetul Sheth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i cannot get you.. Can simplyt make change in code and reply so that i can get exact idea.
 
Norm Radder
Rancher
Posts: 3353
33
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please wrap posted code in code tags.  Select the code and press the Code button above the input box.

This line of code:
String serverName = args[0];
tries to access the first element in the args array  but the args array is empty.

The elements in the args array come from the command line.  For example:
java GreetingClient ArgOne ArgTwo
would put ArgOne and ArgTwo into the String array args so that the program can access them

The code should test for the needed two args before trying to access them and show a message to the user if there are not two args:
 
Hetul Sheth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you just show me how to do it... i am not getting it.. Show changes in my code so that i can apply it..
 
Norm Radder
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the lines of code I showed to your code first thing in the main method, before the code tries to use the contents of the args array.

How are you executing the program?  There needs to be some arguments passed on the command line that will go into the String array passed to the main method.  See my earlier posts.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!