Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
Hello! I am having an hard time with a code from my teacher book.
In the Code I must display the divisors.
I get this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Display.main(afisare.java:7)


I am really frustrating , can you help me ? Here code:
class Display
{
public static void main(String args[ ] )
{
 	int nr=Integer.parseInt(args[0]);
 	int i;
for (i=1; i<=nr; i++)
if (nr%i==0)
System.out.println(i);
}// main
}// class




Sorry My English , I am from Middle Europe.

What I have tried:

I really dont know why I get this error , can someone explain me , pleaseee !
Posted
Updated 30-Oct-18 4:42am
Comments
Bryian Tan 26-Oct-18 16:22pm    
Did you pass in a command line argument when running it?
WalterCC 27-Oct-18 15:11pm    
i dont get it , sorry . I firstly write the code multiple times and run it , and still not work , then I just copy paste it from my teacher pdf book ,still not running.
AstiAsti 27-Oct-18 20:04pm    
The code is not the problem per se ( although a simple check in the code could stop this problem ), do a google search for “command line arguments in jCreator”, this should hopefully point you in the right direction.
WalterCC 28-Oct-18 10:48am    
i did , no solve

1 solution

Ty changing your code from
public static void main(String args[ ] )

to
public static void main(String[] args)

That should solve the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900