Java NullPointerException in agent based model -
i using mason library run simple agent-based model.
as per specifications, meant access agent's inspector double-clicking on such agent in portrayal.
however, when following console error:
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ sim.display.display2d.createinspectors(display2d.java:1737) @ sim.display.display2d$8.mouseclicked(display2d.java:1392) i went display2d.java:1737 find:
public void createinspectors( final rectangle2d.double rect, final guistate simulation ) { bag inspectors = new bag(); bag names = new bag(); bag[] hitobjects = objectshitby(rect); for(int x=0;x<hitobjects.length;x++) { fieldportrayal2dholder p = (fieldportrayal2dholder)(portrayals.get(x)); for( int = 0 ; < hitobjects[x].numobjs ; i++ ) { locationwrapper wrapper = (locationwrapper) (hitobjects[x].objs[i]); inspectors.add(p.portrayal.getinspector(wrapper,simulation)); names.add(p.portrayal.getname(wrapper)); } } simulation.controller.setinspectors(inspectors,names); //1737 } however, library file i'm not familiar it.
any advice?
library: cs.gmu.edu/~eclab/projects/mason/
update:
ok, gets interesting...
i did echo on tostring method of inspectors , names, returning:
insepectors sim.util.bag@1b2202a names sim.util.bag@16b334d ok they're bags, type of collection. time sizes...
insepectors 1 names 1 good, they're not empty.
let's follow error stack
next bit:
at sim.display.display2d$8.mouseclicked(display2d.java:1392) // add mouse listener inspectors insidedisplay.addmouselistener(new mouseadapter() { public void mouseclicked(mouseevent e) { if (handlemouseevent(e)) { repaint(); return; } else { // care mouse button 1. perhaps in future may eliminate key modifiers int modifiers = e.getmodifiers(); if ((modifiers & e.button1_mask) == e.button1_mask) { final point point = e.getpoint(); if( e.getclickcount() == 2 ) 1392-> createinspectors( new rectangle2d.double( point.x, point.y, 1, 1 ), display2d.this.simulation ); if (e.getclickcount() == 1 || e.getclickcount() == 2) // in both situations performselection( new rectangle2d.double( point.x, point.y, 1, 1 )); repaint(); } } } ok, error in createinspectors method:
public void createinspectors( final rectangle2d.double rect, final guistate simulation ) { bag inspectors = new bag(); bag names = new bag(); bag[] hitobjects = objectshitby(rect); for(int x=0;x<hitobjects.length;x++) { fieldportrayal2dholder p = (fieldportrayal2dholder)(portrayals.get(x)); for( int = 0 ; < hitobjects[x].numobjs ; i++ ) { locationwrapper wrapper = (locationwrapper) (hitobjects[x].objs[i]); inspectors.add(p.portrayal.getinspector(wrapper,simulation)); names.add(p.portrayal.getname(wrapper)); } } system.out.println("insepectors " + inspectors.size() + " names " + names.size()); simulation.controller.setinspectors(inspectors,names); } first thing do:
system.out.println(rect.getcenterx() + " " + rect.getcentery()); which gives me 646.5 659.5. seem make sense coordinates.
so next thing want @ hitobjects:
system.out.println(hitobjects.length); returns 2. had 2 agents @ coordinates.
i assume npe somewhere here:
for(int x=0;x<hitobjects.length;x++) { fieldportrayal2dholder p = (fieldportrayal2dholder)(portrayals.get(x)); for( int = 0 ; < hitobjects[x].numobjs ; i++ ) { locationwrapper wrapper = (locationwrapper) (hitobjects[x].objs[i]); inspectors.add(p.portrayal.getinspector(wrapper,simulation)); names.add(p.portrayal.getname(wrapper)); } } the outer loop looks fine, i'm having issues inner one. advice?
i'm going write how reason through library code given far you've come since sound capable.
you found code. that's start. you've found line it's on:
simulation.controller.setinspectors(inspectors,names); //1737 and given know npes can reason simulation or controller null.
do know which? can reason code may have failed set, or passed incorrectly? can put debugger breakpoint or simple println statements in code determine which?
if not , you're using ide (you are), source opened up, put breakpoint before line 1737. when line reached, use debugger inspect variable simulation simulation.controller see null. how depend on ide shouldn't hard find using xkcd's tech support cheat sheet.
then know cause. if not, continue reading source code, e.g. level line 1737.
Comments
Post a Comment