Need help giving thesame error over and over again

Hi all,

The code below is the code for getting the factorial of a number. The program takes the input from the user and checks if it is correct and does the factorial and gives a result according if it is over 20 or not. The problem is that i tried to run, it gives me the same error everytime.Could someone run it too and see what the problem is. By the way the error i was getting was:

init:

deps-jar:

compile-single:

run-single:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

at Factorial.getInput(Factorial.java:30)

at Factorial.main(Factorial.java:11)

Java Result: 1

BUILD SUCCESSFUL (total time: 0 seconds)

import java.math.*;

import javax.swing.*;

publicclass Factorial{

publicstaticvoid main(String[] args){

int n;

try{

n = getInput(args);// can throw InvalidInput

int nfac;

try{

nfac = fac(n);// can throw Overflow

System.out.println(n +"! = " + nfac);

}

catch(Overflow e){

System.out.println("abnormal termination of fac()");

System.out.println("no result available");

}

}

catch(InvalidInput e){

System.out.println("abnormal termination of getInput()");

System.out.println("no result available");

}

}

publicstaticint getInput(String[] args)throws InvalidInput{

int n = Integer.parseInt(args[0]);

if (n < 0)

thrownew InvalidInput("negative input not allowed!");

System.out.println("normal termination of getInput()");

return(n);

}

publicstaticint fac(int k)throws Overflow{

int kk, kfac = 1;

for (kk = 1; kk <= k; kk++){

if (kfac > Integer.MAX_VALUE / (kk + 1))

thrownew Overflow("overflow!");

kfac *= kk;

}

System.out.println("normal termination of fac()");

return kfac;

}

}

class InvalidInputextends Exception{

InvalidInput(){}

InvalidInput(String s){System.out.println(s);}

}

class Overflowextends Exception{

Overflow(){}

Overflow(String s){System.out.println(s);}

}

[4486 byte] By [obenera] at [2007-11-26 19:50:25]
# 1
You're passing an array of zero elements to that method, and expecting that it contains at least one element.I would guess that you aren't passing any arguments to your application on the command line.java Factorial arguments go here
warnerjaa at 2007-7-9 22:39:49 > top of Java-index,Java Essentials,Java Programming...
# 2

when you mean command line do you mean cmd?

i tried using:

java Factorial 2

and i get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Factorial

I know netbeans has an input place in the output box but i seem to have lost it

obenera at 2007-7-9 22:39:49 > top of Java-index,Java Essentials,Java Programming...
# 3
http://onesearch.sun.com/search/onesearch/index.jsp?qt=Exception+in+thread+%22main%22+java.lang.NoClassDefFoundError&subCat=&site=dev&dftab=&chooseCat=javaall&col=developer-forums
CeciNEstPasUnProgrammeura at 2007-7-9 22:39:49 > top of Java-index,Java Essentials,Java Programming...
# 4

> when you mean command line do you mean

> cmd?

Yes.

>

> i tried using:

>

> java Factorial 2

>

> and i get the following error:

>

> Exception in thread "main"

> java.lang.NoClassDefFoundError: Factorial

Then your classpath is wrong - java can't find your class, and it does so via the classpath.

java -classpath . Factorial (arguments go here)

(assuming current directory (.) contains your compiled Factorial class

This is the #1 common newbie issue.

> I know netbeans has an input place in the output box

> but i seem to have lost it

Well, you'd better find it then. This isn't a netbeans support forum.

warnerjaa at 2007-7-9 22:39:49 > top of Java-index,Java Essentials,Java Programming...
# 5
thanks warnerja. it worked.since i was using netbeans,it was putting them in different folders. that solved my problem by putting them in the same folder.by the way do you know where the netbeans forum is?i lost my way.lol.
obenera at 2007-7-9 22:39:49 > top of Java-index,Java Essentials,Java Programming...