Something wrong with random generator...

Hi guys, im having a problem with my code. For some reason my code is not generating a number for me. Instead of pasting ALL of the code related to it, ill just state my variables and give the code thats related.
import java.util.*;
public static Random randomGenerator;
randomGenerator = new Random();
ok this is the code(ignore the system.out.println, i was using it to check where the problem in my code was):
public static void stochasticHillClimberSearch(int lecture, int studentID){
//methods ommited//
for(int i = 0; i < anyAscent; i++){
int chooseRoom = 0;
int chooseTeacher = 0;
fitnessValue = 0;
System.out.println("Made into loop");
//randomly choose the solutions for our search
int chooseDay = randomGenerator.nextInt(5);
int chooseTime = 1;
System.out.println("made through genetaor"+chooseDay);
calculateRoomFitness(chooseDay,chooseTime,chooseRoom,studentID); //call the room fitness method using variables declared
calculateTeacherFitness(chooseDay,chooseTime,chooseTeacher,module); //call the teacher fitness method using variables declared
calculateStudentFitness(chooseDay,chooseTime,studentID); //call the student fitness method using variables declared
compareFitnessValues(fitnessValue,chooseDay,chooseTime,chooseTeacher,chooseRoom); //compare the fitness value method
The problem is my number is not generating, my terminal is printing:
Made into loop
made through genetaor
Made into loop
made through genetaor
Made into loop
made through genetaor
Made into loop
and you'll notice that there is no number printed. The error im getting is:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
     at ConstraintSearch.doRandom(ConstraintSearch.java:175)
     at ConstraintSearch.stochasticHillClimb(ConstraintSearch.java:147)
     at Main.anyAscentSearch(Main.java:303)
     at Main.stochButtonPress(Main.java:1111)
     at Main.access$1500(Main.java:16)
I don't have any idea where the nullpointer is coming from, but im hoping one of you guys are able to tell me :). Many thanks in advance

jennylijava wrote:
How is the randomGenerator null? Since you've shown neither your real code, nor an SSCCE, with code tags and indentation, of course, I can't answer that.
However, if that's line 175, then it absolutely IS null.
Ive initialised the randomGenerator by typing:
randomGenerator = new Random() in my constructor method.So you claim. The JVM thinks otherwise. I'm more inclined to believe it than you (or any other programmer, including myself).
My guess, based on the limited information you've provided, is that either a) you're never calling that constructor, or b) that constructor has a local variable that's hiding the member variable.
Edited by: jverd on Feb 22, 2009 2:02 PM

Similar Messages

  • There is something wrong with the forum

    There is something wrong with the forum. it is messed up.!
    I been a little bit observant this past few days, I observed alot of problems..
    here are a few, ( there are actually alot more, but I could not describe it. its just very weird.
    I thought someone hacked to my profile and used it to ask that one, but when I clicked on it, it was just one of the questions I have responded to.
    sometimes I can not post to threads, an error would come up, most especially if I reply to a reply,
    sometimes, when I Post images it would work the first time I post it, but when I search for it again, only the links are given, no images anymore.
    sometimes I get booted out randomly, in the middle of writing a reply
    sometimes the posts switches from threaded to flat , flat to threaded, and sometimes both.
    sometimes when I checked on the stuffs>discussion, the post is highlighted but there is no new response or like, and even there was, I can see which one is it, especially to the posts that had many reply already
    sometimes it still sends email to my gmail eventhough i have unsubscribe to the post already,
    sometimes get error 504, and some other numbers I forgot.
    sometimes during writing a response the blinking thing that indicates where are you writing goes missing or on the wrong place.
    OH come on..! I am trying to help, you don't want one?
    and don't blame it on ,my browser ( i checked and used IE9, FIREFOX, and even CHROME), or to my internet connection.( i got the best there is for home connections), or to my laptop ( it's a little bit old, but it still kicks butt holes) and tried it already with other pc/internet connection/and whatnot.
    I am still sometimes visiting my previous home (NOKIA FORUM) and I don't experience those, and we even have live chat over there,
    this forum needs a revamp. and how I wish this could be repaired via Sony Update Service, or PC Companion, but of course if it was possible I would have done it already.
    We try to help users, make the forum conducive for users trying to help users. \m/
    best of luck,,
    MARLON LB :smileywink:

    This is how the forum looks for me.
    But during around midnight, (gmt +8) the forum changes to this

  • My phone wont let me download anything even free stuff or update.it keep saying something wrong with my billing info so i fix it but still cant download.I signed out sign back in still nothing please help i'm getting angry

    My phone wont let me download anything even free stuff or update.it keep saying something wrong with my billing info so i fix it but still cant download.I signed out sign back in still nothing please help i'm getting angry

    If it says your billing info is wrong that means that your credit card issuer is refusing to approve your account. You will have to solve the problem with your bank or credit card company.

  • I have a Mid 2009 Macbook Pro 13 with no restore disk; it has OS 10.8.4 I believe there is something wrong with the OS due to I can not install flash player to view Youtube videos and the when we plug in a Bose headset the sound out will work sometimes

    I bough a used Macbook Pro mid 2009 that came with OS 10.8.9 it didn't have a backup restore disk with S/N W8******66D
    When trying to view some youtube videos; a window would pop up saying "it needs adobe flash player is required for video play back get the latest flash player" but after downloading the file and during installation would have errors and will not installed.....tried to reboot and install again.....but still the same.
    The othe thing I had noticed is when using a good Bose headset with mic the sound output would noticed the headset and then switch from headset to Internal speekers and headset.....thinking that there might be something wrong with the plug in port of the computer or the headset.....the headset works with no issues on my iPad so there must be something wrong with the computer.....tried to move the plugin around the port but no change....while the headset is plug in can hear a short clicking noise and the sound would get lost and back again......but with nothing plugin to the port there is no issue with the sound or mic.
    Thanks for your feed back......it looks like I have two different issues one is a software issue and the outher is a hardware issue
    <Edited By Host>

    The "restore disk" is built into the Mac. See About Recovery.
    Need more specifics about what error messages you got while installing Adobe Flash.
    However, you can almost avoid Flash altogether by setting YouTube to play the HTML5 version instead.
    Click the Try something new! link at the bottom of the YouTube page.
    I don't know about the sound issue. Might be hardware as you think. Try other headphones to check.

  • I'm not able to down load free apps without money on a credit card but the app is fee is this correct or is something wrong with my ipad

    I can not download apps that are free without money on a credit card. Is this right or is something wrong with my ipad

    Read here... https://discussions.apple.com/thread/5979741
    Keeka36 wrote:
    is something wrong with my ipad
    No.

  • There is something wrong with the volumes buttons in my macbook pro, every time i pressed the one who raises the volume, it leads me to the screen where (i do not no what its called) the background is black with the date and time and a calculator.

    There is something wrong with the volumes buttons in my macbook pro, every time i pressed the one who raises the volume, it leads me to the screen where (i do not no what its called) the background is black with the date and time and a calculator. However, when i lower it, my safari tab goes out of the screen. What do you guys think i should do? I'm getting very nervous.

    hey HAbrakian!
    You may want to try using the information in this article to adjust the behavior of your function keys to see if that resolves the behavior:
    Mac OS X: How to change the behavior of function keys
    http://support.apple.com/kb/ht3399
    Take care, and thanks for visiting the Apple Support Communities.
    -Braden

  • There is always a blue screen appears after the Apple logo during the booting process. And then everything is back to normal. What is this thing? Is there something wrong with my screen or something?

    There is always a blue screen appears after the Apple logo during the booting process. And then everything is back to normal. What is this thing? Is there something wrong with my screen or something?

    Nah - that's just the normal boot process.
    Clinton

  • I synced. All my music disappeared. Now it will only sync my apps and not my music. Is something wrong with the port on my ipod, the USB cord, or Itunes?On Itunes it says I still have all my music. :(

    I synced my ipod to my computer and all my music disappeared. I tryed resyncing it and it would only sync my apps and not my music. I cant add music to my ipod. I something wrong with the USB port in the IPOD, the USB Cord, or ITUNES itself. Itunes still shows that all my music is there on my ipod. Itunes is recognizing that my ipod is connected, but it doesnt recognize that theres no music on my ipod anymore. Im so sad. Someone please help me. I miss my music.

    The music sync is one way - computer to ipod.  The only exception is itunes purchases.
    The ipod is not a storage/backup device.  It simply mirrors the selected content of your computer.
    As the music came from your computer in the first place, it should still be there and in your backup copy of your computer.

  • "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Getting error message as shown: "The file 'Acknowledgements.rtf' cannot be installed because the file cannot be found in the cabinet file 'iTunes.cab'.  Is there something wrong with the latest installer? (11.3.1)

    Installs fine for me, so I'd guess you got an incomplete or corrupt download. See the Further Information area of Troubleshooting issues with iTunes for Windows updates for direct links and download a fresh copy of the installer.
    tt2

  • Something wrong with my CD/DVD drive??

    I think there is something wrong with my CD/DVD drive. here are the things I notice:
    At time the CD drive will act up and make a little noise (same normal noise as when mac starts up) but for no reason
    When I put my mac on stand by, my CD drive decided to make some noise and then it woke the computer from sleep mode
    Any suggestions? What could be the problem here?
    Thanks.
    Dorian

    well i live in a small town so finding an apple repair service is out of the question....but i will probably just make an appointment....now my biggest problem is i cant find the receipt from best buy where i bought it from. but as soon as i got home and turned it on i registered it online and when i went to check it earlier and typed the serial number it says its still under limited warranty until january 18 2008...can i just tell them the serial number since i dont have the receipt anymore or will they charge me since i dont have the receipt? should i just buy applecare before i make an appointment and bring it in? thanks for all of your help

  • I just purchased Final Cut Pro X and I want to burn a dvd but the tabs do not see the option of SHARE. Is there something wrong with my Final Cut Pro X?

    I just purchased Final Cut Pro X and I want to burn a dvd but the tabs do not see the option of SHARE. Is there something wrong with my Final Cut Pro X?

    It's also under the File menu.

  • Just got an Ipad and am working on setting it up.  the one issue I am having with it is my screen will not rotate no matter what I do to the settings, I can't figure out if the settings are wrong or if there really is something wrong with my Ipad.

    just got an Ipad and am working on setting it up.  the one issue I am having with it is my screen will not rotate no matter what I do to the settings, I can't figure out if I have a setting wrong or if there really is something wrong with my Ipad.  any help would be greatly appreciated.

    Double click the home button (square)  and all the things you did are there.keep sliding the bar that will come up on the bottom to the left till it cant go anymore there should be a icon looking like this.press that and it should work
    Good luck hope it works.

  • Is there something wrong with this table row definition?

    I have am supporting a coldfusion app that manipulates several forms.  One one particular page, there is a form that consists of several tables.  The last 3 lines of the last table are
        <tr>
                <td height="35" align="right" valign="middle">Description:</td>
                <td align="left" valign="middle"><input name="tmpPurpose" class="RptStd" size="70" maxlength="100" value="" onblur="document.ExpnDtl.Purpose.value = this.value;" onchange="ChkName(<cfoutput>#Session.CCWarn#</cfoutput>)" /><input type="hidden" name="Purpose" value="" />
                             <a href="#" id="aDesc" onclick="ShowHelp('9')" style="border:none; display:inline; padding: 0px 0px 0px 0px"><img src="/images/Help_Icon.gif" height="14" width="13" border="0" /></a>
                            </td>
          </tr>
          <cfif IsDefined("form.ExpnsCntrb")>
              <tr id="CntrbErr">
                   <td colspan="2" class="Error"><cfoutput>#form.ExpnsCntrb#</cfoutput></td>
              </tr>
          </cfif>
          <tr id="expnContrib">
                  <td align="left" valign="middle" height="35" class="RptStd" colspan="2">Is expenditure a contribution to a candidate, officeholder, or political committee?    <input type="radio" name="rdoCntrb" value="Y" /> Yes    <input type="radio" name="rdoCntrb" value="N" /> No</td>
           </tr>
          <tr id="COHInfo">
              <td colspan="2" class="RptStd" align="left" valign="middle" height="35">
                  <input type="checkbox" name="chkCand" id="chkCand" value="X" onclick="if (this.checked) document.ExpnDtl.btnCOH.disabled = false; else document.ExpnDtl.btnCOH.disabled = true;" />Direct expenditure to benefit a candidate or officeholder    
                  <input type="button" name="btnCOH" value=" Enter C/OH Information " class="RptBtn" onclick="window.open('/Testing/Test_COHBenefit.cfm?Parent=' + document.ExpnDtl.ItemID.value + '&Type=EXPN&Form=' + document.ExpnDtl.ExpnCode.value, 'CandidateInfo', 'width=730px,height=475px,scrollbars,resizable,location')" disabled /> <a href="#" id="aDirExpn" onclick="ShowHelp('11')" style="border:none; display:inline; padding: 0px 0px 0px 0px"><img src="/images/Help_Icon.gif" height="14" width="13" border="0" /></a>
              </td>
         </tr>
         </table>
    Now whne the form is displayed on my page, I always see the line of text Description and the line of text Direct expenditure to benefit a candidate or officholder (in bold above).  But I never see the line of text  Is expenditure a contribution to a candidate... (in italics above).   It seems so simple but I can't figure out why that line does not display!!  Is there something wrong with that tr/td definition?

    Have you tried removing the ID?  Just to see if some CSS might be using that ID with a display:none or visibility:none statement?

  • Is there something wrong with a Oscar Gomez Fuentes 2Channel oscilloscope

    Is there something wrong with a Oscar Gomez Fuentes 2Channel oscilloscope or are my devices configured wrong. I have DAQCard-6036E and SCC-2345 with SCC-Ft01 and SCC-A10 modules. The problem is that when I am measuring with A10 it effects to FT01's RMS and DC values. But when I am measuring with Ft01 everything is ok. So what's wrong?? I attached a picture of a front panel.
    Attachments:
    front_panel.JPG ‏132 KB

    Neuvos,
    Do any of the signals you are measuring have high output impedances (> 1 kOhm)? If so, you may be seeing cross-talk (or ghosting). Below, I have included links to a number of documents that discuss this issue and methods for eliminating it:
    Data Acquisition: Troubleshooting Unexpected Voltages or Cross-talk in Analog Input Channels
    Using a Unity Gain Buffer (Voltage Follower) with a DAQ Device
    Is Your Data Inaccurate Because of Instr
    umentation Amplifier Settling Time?
    Good luck with your application.
    Spencer S.

  • Is there something wrong with my Retina Macbook Pro?

    I have been looking at the Geekbench scores for the new retina model with 2.6GHz and 8GB of RAM and they are getting around 11-12 thousand as there final score. When I do it (I have the 2.6GHz model), I receive a score between 5-6 thousand. Is something wrong with my computer, or what?

    You can't really do a benchmark on your MB if you're running on batteries.
    Keep in mind, when you're running on batteries, your MB is not using your CPU's full potential since it's on power saving mode.
    Too do a proper benchmark, your MB must be plugged in to take advantage of your CPU's full power and your graphic card's power.
    I for one do not follow benchmarks anymore.  I used to when I used to build my own gaming rig with all the bells and whistles.
    But to be honest, you will never, ever put your MB in such extreme.
    If you're still not satisfied with your MB's performace, you can either follow or ignore my or sig's comments.

Maybe you are looking for