Exception in thread main java.lang.NullPointerException

Discussion in 'Programmer's Corner' started by Ben_C, May 3, 2012.

  1. Ben_C

    Thread Starter Active Member

    Oct 19, 2010
    65
    4
    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)

    Code ( (Unknown Language)):
    1. public class MTBFTester
    2.  {
    3.         public static void main (String [] args)
    4.         {
    5.         usage(args);
    6.         MTBFCalculator calc = new MTBFCalculator(args);
    7.         calc.getMTBF();
    8.         }
    9.         private static void usage(String [] test)
    10.         {
    11.         if (test.length<2)
    12.         {
    13.         System.out.println("usage: java MTBFTester <1st value> <2nd
    14. value> ...");
    15.         }
    16.     }
    17. }
    18.  
    19. //This is the other class
    20. class MTBFCalculator
    21. {
    22.  
    23. //fields
    24.         String [] argsArray;
    25.         double [] doublesArray;
    26. //constructor
    27.         public MTBFCalculator(String [] data)
    28.         {
    29.         for(int i=0; i<data.length; i++)
    30.  {
    31.         argsArray [i] = data [i];
    32.         }
    33.         doublesArray = new double[argsArray.length];
    34.         }
    35. //method
    36.         public void getMTBF()
    37.         {
    38.         for(int i=0; i<argsArray.length; i++)
    39.         {
    40.         doublesArray[i] = Double.parseDouble(argsArray[i]);
    41.         if (doublesArray[i] < 1)
    42.         {
    43.         System.out.println("zero or negative values are not accepted");
    44.         }
    45.                 }
    46.                 double testMTBF = 0;
    47.                 double MTBF = 0;
    48.                 for(int i=0; i<doublesArray.length; i++)
    49.                 {
    50.                 testMTBF = testMTBF + 1/doublesArray[i];
    51.                 }
    52.                 MTBF = 1/testMTBF;
    53.                 System.out.println("" + MTBF);
    54.        }
    55. }[/i][/i][/i][/i][/i][/i]


    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 :p
     
Loading...