Hi im getting 2 errors when im trying to run my comman line arguments.. Its giving me the errors:
Exception in thread "main" java.lang.NullPointerException
at MTBFCalculator.<init>(MTBFTester.java:37)
at MTBFTester.main(MTBFTester.java:7)
In cmd im copiling it then on the next command line im passing numeric values but get the errors.
Anybody help it needs to be handed in in like 15 hours
Exception in thread "main" java.lang.NullPointerException
at MTBFCalculator.<init>(MTBFTester.java:37)
at MTBFTester.main(MTBFTester.java:7)
Rich (BB code):
public class MTBFTester
{
public static void main (String [] args)
{
usage(args);
MTBFCalculator calc = new MTBFCalculator(args);
calc.getMTBF();
}
private static void usage(String [] test)
{
if (test.length<2)
{
System.out.println("usage: java MTBFTester <1st value> <2nd
value> ...");
}
}
}
//This is the other class
class MTBFCalculator
{
//fields
String [] argsArray;
double [] doublesArray;
//constructor
public MTBFCalculator(String [] data)
{
for(int i=0; i<data.length; i++)
{
argsArray = data ;
}
doublesArray = new double[argsArray.length];
}
//method
public void getMTBF()
{
for(int i=0; i<argsArray.length; i++)
{
doublesArray = Double.parseDouble(argsArray);
if (doublesArray < 1)
{
System.out.println("zero or negative values are not accepted");
}
}
double testMTBF = 0;
double MTBF = 0;
for(int i=0; i<doublesArray.length; i++)
{
testMTBF = testMTBF + 1/doublesArray;
}
MTBF = 1/testMTBF;
System.out.println("" + MTBF);
}
}
In cmd im copiling it then on the next command line im passing numeric values but get the errors.
Anybody help it needs to be handed in in like 15 hours