Return-Path: <ssiegel@MIT.EDU>
Received: from grand-central-station.mit.edu by po11.mit.edu (8.9.2/4.7) id NAA06362; Fri, 16 Aug 2002 13:46:51 -0400 (EDT)
Received: from manawatu-mail-centre.mit.edu (MANAWATU-MAIL-CENTRE.MIT.EDU [18.7.7.71])
	by grand-central-station.mit.edu (8.9.2/8.9.2) with ESMTP id NAA21512
	for <sipb@mit.edu>; Fri, 16 Aug 2002 13:44:40 -0400 (EDT)
Received: from balder.mit.edu (BALDER.MIT.EDU [18.170.0.150])
	by manawatu-mail-centre.mit.edu (8.9.2/8.9.2) with ESMTP id NAA01481
	for <sipb@mit.edu>; Fri, 16 Aug 2002 13:44:40 -0400 (EDT)
Received: from localhost (ssiegel@localhost) by balder.mit.edu (8.9.3) with ESMTP
	id NAA05997; Fri, 16 Aug 2002 13:44:39 -0400 (EDT)
Date: Fri, 16 Aug 2002 13:44:39 -0400 (EDT)
From: Sarah Y Siegel <ssiegel@MIT.EDU>
To: <sipb@mit.edu>
Subject: java question
Message-ID: <Pine.GSO.4.30L.0208161340540.5699-100000@balder.mit.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

The answer to this email suggested that I contact you guys. Can you help
me?

Thanks.

-----Original Message-----
Date: Fri, 16 Aug 2002 13:14:35 -0400
To: computing-help@MIT.EDU
From: Sarah Y Siegel <ssiegel@MIT.EDU>
Cc:
Subject: java


Can you guys help me with a java programming question, or is that more
specific than you guys get into? I'm guessing it's too specific. If you
can't, do you have a suggestion as where I could get help? I'm a grad
student using java for a research project, and I so far haven't found
anyone in the department who can help me out. And although over the
summer I've had a couple friends I've asked for help, it would be great
to have a consultant I could ask. This is my current question, which is
on a program I've written using the java libraries RePast
(repast.sourceforge.net):

> So I'm trying to set my simulation to run in batch mode so I
 > can collect some
 > data. So I set it up with a data recorder, everything works
 > fine. Then I changed
 > one line, from
 >
 > init.loadModel(model, null, false);  to
 > init.loadModel(model, "./Params.txt", true);
 >
 > so I changed the parameters file from nothing to one that I
 > wrote, and then
 > changed the batch file parameter from false to true.
 >
 > It now compiles fine, but when I try to run it it gives me
 > null pointer
 > exceptions at these lines:
 >         x = Random.uniform.nextIntFromTo(0,width-1);
 >         y = Random.uniform.nextIntFromTo(0,height-1);
 >
 > I put in some print commands to see what was going on, and it
 > does have the
 > right, nonzero, integer values for width and height. Any ideas? I
just
 > can't figure out
 > what in the world those lines could possibly have to do with
 > running it as a
 > batch file.

 > Thanks!
 >
 > Sarah
 >
 > p.s. Here's more of my code, iwth all the stuff I put in to
 > try to figure out
 > what was going on and the error I get in case that
 > helps--log() is a method that
 > prints out what's in the parentheses.
 >
 >     public static void main(String[] args) {
 >         uchicago.src.sim.engine.SimInit init =
 >             new uchicago.src.sim.engine.SimInit();
 >         FixedSchellingModel model = new FixedSchellingModel();
 >         init.loadModel(model, "./Params.txt", true);
 >         //init.loadModel(model, null, false);
 >     }
 >
 >     public void setup() {
 >         super.setup();
 >         if (dsurf != null) dsurf.dispose();
 >
 >                System.gc();
 >         log("setting up");
 >         dsurf = new DisplaySurface(this, "FixedSchelling Display");
 >         registerDisplaySurface("Main", dsurf);
 >         generateNewSeed();
 >         Random.createUniform();
 >
 >         BaseController c = getController();
 >         c.setCellHeight(cellSize);
 >         c.setCellWidth(cellSize);
 >         c.setCellDepth(cellSize);
 >         setStoppingTime(5);
 >     }
 >     public void buildModel() {
 >
 >         // the "true" or "false" parameter refers to whether
 > the space should be a
 > torus
 >         space = new FixedSchellingSpace(width, height, false, this);
 >         setupSpace();
 >         display = space.getDisplay();
 >         dsurf.addDisplayableProbeable(display, "FixedSchelling
 > Display");
 >         ((Object2DDisplay)display).setObjectList(agentList);
 >         dsurf.display();
 >         buildCharts();
 >         recorder = new DataRecorder("./data815.txt", this);
 >         recorder.addNumericDataSource("avgUtility", new
 > NumDataSource());
 >     }
 >
 >
 >     public void setupSpace() {
 >         //log("random placement");
 >         double n = ((double)(width * height)*(1-(vacancies/100)));
 >         int n1 = (int)Math.round(n*type1percent/100);
 >         int n2 = (int)Math.round(n-n1);
 >         //log("n1 = " + n1 + " and n2 = " + n2 + " and width =
 > " + width + " and height
 > = " + height);
 >         for (int i= 0; i < n1; i++){
 >             int x = 10;
 >             try{
 >                 x = Random.uniform.nextIntFromTo(0,width-1);
 >             }
 >             catch (NullPointerException e){
 >                 log("something weird here");
 >
 >             }
 >
 >             int y = Random.uniform.nextIntFromTo(0,height-1);
 >             //   System.out.println("checking if empty at " + x
 > + ", " + y);
 >             while (!space.isEmptyAt(x,y)){
 >                 x = Random.uniform.nextIntFromTo(0,width-1);
 >                     y = Random.uniform.nextIntFromTo(0,height-1);
 >             }
 >             FixedSchellingAgent agent = new
 > FixedSchellingAgent(x, y, 1, 11, space);
 >             space.addAgent(agent);
 >             agentList.add(agent);
 >         }
 >
 >         for (int i= 0; i < n2; i++){
 >             int x = Random.uniform.nextIntFromTo(0,width-1);
 >             int y = Random.uniform.nextIntFromTo(0,height-1);
 >             while (!space.isEmptyAt(x,y)){
 >                 x = Random.uniform.nextIntFromTo(0,width-1);
 >                     y = Random.uniform.nextIntFromTo(0,height-1);
 >             }
 >             FixedSchellingAgent agent = new
 > FixedSchellingAgent(x, y, 2, 21, space);
 >             space.addAgent(agent);
 >             agentList.add(agent);
 >         }
 >
 >     }
 >
 >     public void step() {
 >
 >         //log("stepping!");
 >         SimUtilities.shuffle(agentList);
 >         int size = agentList.size();
 >         for (int i = 0; i < size; i++) {
 >             FixedSchellingAgent agent =
 > (FixedSchellingAgent)agentList.get(i);
 >             agent.step();
 >         }
 >         graph.step();
 >         dsurf.updateDisplay();
 >         recorder.record();
 >     }
 >
 > and what prints out is:
 >
 > setting up
 > Run: 1
 > something weird here
 > java.lang.NullPointerException
 >         at
 > edu.santafe.csss.fixedschelling.FixedSchellingModel.setupSpace
 > (FixedSchellingModel.java:146)
 >         at
 > edu.santafe.csss.fixedschelling.FixedSchellingModel.buildModel
 > (FixedSchellingModel.java:119)
 >         at
 > uchicago.src.sim.engine.SimpleModel.begin(SimpleModel.java:104)
 >         at
 > uchicago.src.sim.engine.BaseController.startSim(BaseController
 > .java:345)
 >         at
 > uchicago.src.sim.engine.BatchController.start(BatchController.
 > java:412)
 >         at
 > uchicago.src.sim.engine.BatchController$1.run(BatchController.
 > java:383)
 >         at java.lang.Thread.run(Thread.java:484)
 > Batch Done
 >
 >
 >

