i not @ oop, got problem constructor not returning anything.
public class crossentropy extends thread{ protected cemobileagentmigrationplan appowner; private sensornode[] sensornodes; private jlabel status; private jtextarea textarea; integer temp = null; boolean first=true; int tempor; int populasi=1000; double = 0.8; double g=(int)(populasi/3); int max=appowner.sensorcount+populasi; private double costa=0; private int[] samatidak; public int[] mem; private double[] sortbox; private double w[][] = new double[max][max]; private double p[][] = new double[max][max]; private double[][] pn; private int[][] jalur; private double[] cost; boolean first2; public crossentropy(cemobileagentmigrationplan appowner){ system.out.println("hi !"); this.appowner=appowner; system.out.println("hi hi hello !"); this.sensornodes=appowner.sensornodelist; system.out.println("hello !"); } //method shortened public void run(){//engga kepanggil system.out.println("testtament"); double time = system.currenttimemillis(); double thiscost = 0.0; double oldcost = 0.0; int countsame=0; int duration=0; double hasilakhir =0; boolean cek = false; //matrikrate(); while (countsame<1000){ membangkitkantour(); getcost(); thiscost = costa; if (cek==false){ oldcost=thiscost; cek=true; } if (thiscost<oldcost){ oldcost=thiscost; costa=0; getcost(); hasilakhir=costa; countsame=0; }else{ countsame++; //appowner.paint(); } costa=0; } duration = (int) (system.currenttimemillis()-time); stringbuffer sb = new stringbuffer(); (int i=0; i< appowner.sensorcount; i++){ sb.append("node address: " + appowner.sensornodelist[mem[i]].getaddress()); sb.append(" rssi: " + appowner.sensornodelist[mem[i]].getsignalstrength()); sb.append(" battery level: " + appowner.sensornodelist[mem[i]].getremainingbattery()); sb.append("\n"); } string status = "ce finds solution after " + duration + " ms max rating= " + hasilakhir; string migrationinfo = sb.tostring(); appowner.setstatus(status, "urutan rute migrasi: \n" + migrationinfo); } }
this class want call constructor
public class cemobileagentmigrationplan extends jframe { //protected sensornodeplacementmap map = null; sensornode[] sensornodelist; crossentropy worker; private jtextarea textarea; boolean started = false; private jlabel status; int sensorcount; public cemobileagentmigrationplan(){ getcontentpane().setlayout(new borderlayout()); status = new jlabel("starting app..."); textarea = new jtextarea("listening... \b"); getcontentpane().add(status,borderlayout.south); getcontentpane().add(textarea,borderlayout.center); setsize(500,400); settitle("cross entropy mobile agent itinerary planning"); this.setresizable(true); setvisible(true); } public void setsensornodes(sensornode[] sensornodes){ this.sensornodelist = sensornodes; this.sensorcount = this.sensornodelist.length; } public int getsensorcount(){ return sensorcount; } public sensornode[] getsensornodelist(){ return sensornodelist; } public void setstatus(string statustxt, string migrationinfo){ status.settext(statustxt); textarea.settext(migrationinfo); } public void setsensornodelist(sensornode[] sensornodelist) { this.sensornodelist = sensornodelist; } public void start(){ // yang ini tidak bisa this.started=true; //map.update(map.getgraphics()); //if (worker!= null)worker=null; system.out.println("lol"); worker = new crossentropy(this); <<<<< troublemaker system.out.println("lol1111"); worker.setpriority(thread.min_priority); //map.update(map.getgraphics()); worker.start(); } }
i make similar class find out cause it, couldn't find :(
if code sample provided complete, you'll nullpointerexception when trying construct object. line
int max=appowner.sensorcount+populasi;
will cause it, because appowner null when object constructed. properties initialized before constructor called. should calculate value in construtor itself, e.g.
int max; public crossentropy(cemobileagentmigrationplan appowner){ system.out.println("hi !"); this.appowner=appowner; max=appowner.sensorcount+populasi; system.out.println("hi hi hello !"); this.sensornodes=appowner.sensornodelist; system.out.println("hello !"); }
Comments
Post a Comment