Results 1 to 4 of 4
  1. #1
    TheJavaViking is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default An error I nedd help with

    Hey Guys!

    So I'm doing my project which I have to do in java.
    Its a simulation model that i have to build basically.
    So the are new business branches opening and each one of them generate a task at a specific point, this is a given in the form of an array.

    Tasks = [0,0,2,5,7,10,11,12,13,15,17,19,19,20,22,25,25,28,2 8,30,30,30,30,30,30,32,32,33,33,35,35,35,37,37.... .37]
    This means that in month 1 0 tasks are generated as well as month 2 but in month 3; 2 tasks are generated.
    This means that a maximum of 2 tasks are generated in month 3 and no more and so for each month.
    But for each task that is generated there is a 42% probability that it will be accepted.

    So i thought that i could produce an array per month for the probabilities i.e. 2 tasks 2 probabilities are generated and stored in an array. for month 4; 5 tasks are generated thus 5 probabilites are generated per task.
    The tasks that are accepted go into another array. but that is not the problem.

    i got it working sort of... but keeps giving me an error which is posted.

    Hope someone can help.

    I am new to java, perhaps another way to solve this problem?

    The error :
    Exception in thread "main" java.lang.NullPointerException
    at matrix_a.main(matrix_a.java:82)

    just named it matix_a


    double [][] probabilities = new double[60][];
    //month1
    probabilities[0] = new double [1]; ----- month and the size
    probabilities[0][0] = 0;

    //month2
    probabilities[1] = new double [1]; ----- month and the size
    probabilities[1][0] = 0;

    //month3 - month60

    /*month3*/ probabilities[2] = new double [2]; ----- month and the size
    /*month4*/ probabilities[3] = new double [5];
    /*month5*/ probabilities[4] = new double [7];
    /*month6*/ probabilities[5] = new double [10];
    /*month7*/ probabilities[6] = new double [11];
    /*month8*/ probabilities[7] = new double [12];
    /*month9*/ probabilities[8] = new double [13];
    /*month10*/ probabilities[9] = new double [15];
    /*month11*/ probabilities[10] = new double [17];
    /*month12*/ probabilities[11] = new double [19];
    /*month13*/ probabilities[12] = new double [19];
    /*month14*/ probabilities[13] = new double [20];
    /*month15*/ probabilities[14] = new double [22];
    /*month16*/ probabilities[15] = new double [25];
    /*month17*/ probabilities[16] = new double [25];
    /*month18*/ probabilities[17] = new double [28];
    /*month19*/ probabilities[18] = new double [28];
    /*month20*/ probabilities[19] = new double [30];
    /*month21*/ probabilities[20] = new double [30];
    /*month22*/ probabilities[21] = new double [30];
    /*month23*/ probabilities[22] = new double [30];
    /*month24*/ probabilities[23] = new double [30];
    /*month25*/ probabilities[24] = new double [30];
    /*month26*/ probabilities[25] = new double [32];
    /*month27*/ probabilities[26] = new double [32];
    /*month28*/ probabilities[27] = new double [33];
    /*month29*/ probabilities[28] = new double [33];
    /*month30*/ probabilities[29] = new double [35];
    /*month31*/ probabilities[30] = new double [35];
    /*month32*/ probabilities[31] = new double [35];
    /*month33*/ probabilities[32] = new double [37];
    /*month34*/ probabilities[33] = new double [37];
    /*month35*/ probabilities[34] = new double [37];
    /*month36*/ probabilities[35] = new double [37];
    /*month37*/ probabilities[36] = new double [37];
    /*month38*/ probabilities[37] = new double [37];
    /*month39*/ probabilities[38] = new double [37];
    /*month40*/ probabilities[39] = new double [37];
    /*month41*/ probabilities[40] = new double [37];
    /*month42*/ probabilities[42] = new double [37];
    /*month43*/ probabilities[42] = new double [37];
    /*month44*/ probabilities[43] = new double [37];
    /*month45*/ probabilities[44] = new double [37];
    /*month46*/ probabilities[45] = new double [37];
    /*month47*/ probabilities[46] = new double [37];
    /*month48*/ probabilities[47] = new double [37];
    /*month49*/ probabilities[48] = new double [37];
    /*month50*/ probabilities[49] = new double [37];
    /*month51*/ probabilities[50] = new double [37];
    /*month52*/ probabilities[51] = new double [37];
    /*month53*/ probabilities[52] = new double [37];
    /*month54*/ probabilities[53] = new double [37];
    /*month55*/ probabilities[54] = new double [37];
    /*month56*/ probabilities[55] = new double [37];
    /*month57*/ probabilities[56] = new double [37];
    /*month58*/ probabilities[57] = new double [37];
    /*month59*/ probabilities[58] = new double [37];
    /*month60*/ probabilities[59] = new double [37];



    for (int i = 2; i < probabilities.length; i++){
    line 82----- for (int k = 0; k < probabilities[i].length; k++){
    probabilities[i][k] = Math.random();
    }
    }
    for (int i = 2; i < probabilities.length; i++){
    for (int j = 0; j < probabilities[i].length; i++){
    System.out.println(probabilities[i][j]);
    }




    }


    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: An error I nedd help with

    Exception in thread "main" java.lang.NullPointerException
    at matrix_a.main(matrix_a.java:82)
    There is a variable on line 82 with a null value. Look at line 82, find the variable with the null value and then backtrack in the code to see why that variable does not have a valid non-null value.

    Please wrap all your code in code tags.
    http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    TheJavaViking is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: An error I nedd help with

    Thanks, made a silly mistake!

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: An error I nedd help with

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 06:26 PM
  2. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  3. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  4. Nedd scjp 1.5 dump
    By dsamba.java in forum Java Certification
    Replies: 0
    Last Post: 11-26-2008, 02:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •