Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 30

Thread: a very confusing exception

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default a very confusing exception

    Problem:
    line 191 to 200
    static void plotsolution(int kmax) {
    		System.out.printf("\n\n");
     
    	    for(int k=0; k<=kmax; k++)
    	    { 
    	    	System.out.printf("%7.5f \t %7.5e \t %7.5e \n", k*dt, y[0][k], y[2][k]);
     
    	    }
     
    	}

    variable declaration
    static  double[][]  y;                        /* vectors for storing solution      */
    static double dt;                             /* DELTA*/

    exeption information
    HTML Code:
    Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'l'
    	at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    	at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    	at java.util.Formatter.parse(Unknown Source)
    	at java.util.Formatter.format(Unknown Source)
    	at java.io.PrintStream.format(Unknown Source)
    	at java.io.PrintStream.printf(Unknown Source)
    	at proxel.MTProxel.plotsolution(MTProxel.java:195)
    	at proxel.MTProxel.main(MTProxel.java:517)
    actually there is nothing at line 517 except a bracket
    It makes me just so confusing!!!!!!!!!

    it will be so good to get some help from you


     
    public static void main(String[] args){
     
    		    /* initialize the simulation */
     
    		    eerror=0.0;
    		    totcnt  = 0;
    		   y=new double[3][kmax+2];
     
     
     
    		    for (int k = 0; k < 3; k++) {
    		    	//..........................
    		        for (int j = 0; j < kmax+2; j++) 
    		        	y[k][j] = 0.0;
    		    }
     
     
    		    /* first loop: iteration over all kmax time steps*/
    		    for (int k = 1; k <= kmax+1; k++) {
     
     
    		        /* second loop: iterating over all proxels of a time step */
    		        while (root[1-sw] != null)
    		        {
    		            y[s][k-1] += val;
     
    .....................................
     
    		    System.out.printf("error = %7.5e\n", eerror); 
     
    		    System.out.printf("ccpx = %d\n", maxccp);
    		    System.out.printf("count = %d\n", totcnt);
    		    System.out.printf("count = %d\n", defective);
     
    		    plotsolution(kmax);
    		    //return 0;
                        }
    }

    The line 517 is the sentence y[s][k-1] += val; which placed in the second loop.
    I have tested the exception causing codes in a simplified test program.It runs ok.


    I copy here the whole program that can be easily executed.

    package proxel;
     
    import java.util.LinkedList;
    import java.util.List;
     
     
    class Proxel {
     
        int     id;                  /* unique proxel id for searching    */
        int     s;                   /* discrete state of SPN             */
        int     tau1k;               /* first supplementary variable      */
        int     tau2k;               /* second supplementary variable     */
        double  val;                 /* proxel probability                */
        Proxel left, right;         /* reference to child proxels in tree */
     
    }
     
     
     
     
    public class MTProxel {
     
    	static  double[][]  y;                        /* vectors for storing solution      */
    	static double  tmax  ;                        /* maximum simulation time           */
    	static int     TAUMAX;                        /*the largest possible aging time    */
     
    	static  int     totcnt;                        /* counts total proxels processed    */
    	static  int     maxccp;                        /* counts max # concurrent proxels   */
    	static  int     ccpcnt ;                       /* counts concurrent proxels         */
     
    	static Proxel[] root=new Proxel[2];           /* trees for organizing proxels      */
     
    	static List<Proxel> firstfree=new LinkedList<Proxel>(); ;                     /* linked list of free proxels       */
    	static double  eerror      = 0;               /* accumulated error                 */
     
    	static int     sw         = 0;                /* switch for old and new time steps */
     
    	static int len;
    	static double dt;                             /* DELTA*/
     
     
    	final static double ENDTIME=10;
    	final static double DELTA=0.005;
    	final static double MINPROB=1.0e-12;
    	final static int HPM=        0;
    	final static int  LPM=       2;
     
    	/********************************************************/
    	/*	distribution functions			                    */
    	/*	instantaneous rate functions			            */
    	/********************************************************/
     
     
    	/* returns weibull IRF */
     
    	static double weibullhrf(double x, double alpha, double beta, double x0) {
    	    double y;
     
    	    y = beta/alpha*Math.pow((x-x0)/alpha,beta-1);
    	    return y;
    	}
     
     
    	/* returns deterministic IRF */
    	static double dethrf(double x, double d) {
    	    double y;
     
    	    if (Math.abs(x - d) < dt/2)
    	        y = 1.0/dt;
    	    else
    	        y = 0.0;
    	    return y;
     
    	}
     
     
    	/* returns uniform IRF */
    	public static double unihrf(double x, double a, double b) {
    	    double y;
     
    	    if ((x >= a) && (x < b))
    	        y = 1.0/(b-x);
    	    else
    	        y = 0.0;
     
    	    return y;
    	}
     
     
     
    	/********************************************************/
    	/*	output functions			                        */
    	/********************************************************/
    	/* print out complete solution */
    	static void plotsolution(int kmax) {
    		System.out.printf("\n\n");
     
    	    for(int k=0; k<=kmax; k++)
    	    { 
    	    	System.out.printf("%7.5f \t %7.5e \t %7.5e \n", k*dt, y[0][k], y[2][k]);
     
    	    }
     
    	}
     
     
    	/********************************************************/
    	/*	proxel manipulation functions			            */
    	/********************************************************/
     
    	/* compute unique id from proxel state */
    	static int state2id(int s, int t1k, int t2k) {
    	    return(TAUMAX*(TAUMAX*s+t1k)+t2k);
    	}
     
    	/* compute size of tree */
    	static int size(Proxel p) {
    	    int sl, sr;
     
    	    if (p == null)
    	        return(0);
    	    sl = size(p.left);
    	    sr = size(p.right);
    	    return(sl+sr+1);
    	}
     
     
     
    	/* get a fresh proxel and copy data into it */
    	static Proxel insertproxel(int s, int tau1k, int tau2k, double val) {
     
    		Proxel temp;
     
    	    /* create new proxel or grab one from free list */
    	    if (firstfree.isEmpty()== true)
    	        temp = new Proxel();
    	    else {
    	    	/*temp = firstfree;
    	        firstfree = firstfree.right;*/
     
    	    	temp=((LinkedList<Proxel>) firstfree).removeFirst();
     
    	    }
    	    /* copy values */
    	    temp.id    = state2id(s, tau1k, tau2k);
    	    temp.s     = s;
    	    temp.tau1k = tau1k;
    	    temp.tau2k = tau2k;
    	    temp.val   = val;
    	    ccpcnt     += 1;
     
    	    //to count the max number of the concurrent Proxel
    	    if (maxccp < ccpcnt) {
    	        maxccp = ccpcnt;
    	        //printf("\n ccpcnt=%d",ccpcnt);
    	    }
    	    return temp;
    	}
     
     
    	/*returns a proxel from the tree*/ 
    	static Proxel getproxel()
    	{
    	    Proxel temp;
    	    Proxel old;
    	    final int LEFT = 0, RIGHT = 1;
    	    int dir=1;                 //to record it is right or left child of its parent
    	    int cont = 1;            //a mark to label if it has been already the leaf
     
    	    if (root[1-sw] == null)
    	        return null;
     
    	    temp = root[1-sw];
    	    old  = temp;
     
    	    /*move down the tree to a leaf */
    	    while (cont == 1)
    	    {
    	        /* go right */
    	        if ((temp.right != null) && (temp.left == null))
    	        {
    	            old  = temp;
    	            temp = temp.right;
    	            dir  = RIGHT;
    	        }
     
    	        /* go left */
    	        else if ((temp.right == null) && (temp.left != null))
    	        {
    	            old  = temp;
    	            temp = temp.left;
    	            dir  = LEFT;
    	        }
     
    	        /* choose right/left at random */
    	        else if ((temp.right != null) && (temp.left != null))
    	        {
     
    	            if (Math.random() >0.5)     // 0.5 is a random bound here,RAND_MAX/2
    	            {
    	                old  = temp;
    	                temp = temp.left;
    	                dir  = LEFT;
    	            }
    	            else
    	            {
    	                old  = temp;
    	                temp = temp.right;
    	                dir  = RIGHT;
    	            }
    	        }
     
    	        else
    	            cont = 0;
    	    }          //end while
     
    	    //remove the proxel which has been returned from the tree
    	    if (temp == root[1-sw])
    	        root[1-sw] = null;
    	    else
    	    {
    	        if (dir == RIGHT)
    	            old.right = null;
    	        else
    	            old.left = null;
    	    }
    	   /*c: old = firstfree;
    	    firstfree = temp;
    	    temp.right = old;
    	    ccpcnt -= 1;*/
     
    	    ((LinkedList<Proxel>)firstfree).addFirst(temp);
     
     
     
    	    return temp ;
    	}
     
    	/* adds a new proxel to the tree */
    	static void addproxel(int s, int tau1k, int tau2k, double val) {
    	    Proxel temp, temp2;
    	    int cont = 1,id;
     
    	    /* Alarm! TAUMAX overstepped! */
    	    if (tau1k >= TAUMAX) {
    	        //  printf(">>> %3d %3d %3d %7.5le \n", s, tau1k, val, TAUMAX);
    	        tau1k = TAUMAX - 1;
    	    }
     
     
    	    /* New tree, add root */
    	    if (root[sw] == null) {
    	        root[sw] = insertproxel(s,tau1k, tau2k, val);
    	        root[sw].left = null;
    	        root[sw].right = null;
    	        return;
    	    }
     
    	    /* compute id of new proxel */
    	    id = state2id(s,tau1k, tau2k);
     
    	    /* Locate insertion point in tree */
    	    temp = root[sw];
    	    while (cont == 1) {
    	        if ((temp.left != null) && (id < temp.id))
    	            temp = temp.left;
    	        else
    	            if ((temp.right != null) && (id > temp.id))
    	                temp = temp.right;
    	            else
    	                cont = 0;
    	    }
     
    	    /* Insert left leaf into tree */
    	    if ((temp.left == null) && (id < temp.id)) {
    	        temp2        = insertproxel(s, tau1k,tau2k, val);
    	        temp.left   = temp2;
    	        temp2.left  = null;
    	        temp2.right = null;
    	        return;
    	    }
     
    	    /* Insert right leaf into tree */
    	    if ((temp.right == null) && (id > temp.id)) {
    	        temp2        = insertproxel(s, tau1k,tau2k, val);
    	        temp.right  = temp2;
    	        temp2.left  = null;
    	        temp2.right = null;
    	        return;
    	    }
     
    	    /* Proxels have the same id, just add their vals */
    	    if (id == temp.id) {
    	        temp.val += val;
    	        return;
    	    }
    	    System.out.printf("\n\n\n!!!!!! addproxel failed !!!!!\n\n\n");
    	}
     
     
     
     
    	/********************************************************/
    	/*	model specific distribtuions	                    */
    	/********************************************************/
     
     
    	/* INSTANTANEOUS RATE FUNCTION 1 */
    	static double hpm2lpm(double age) {
    	    //return unihrf(age, 0.25, .5);
     
    	    return weibullhrf(age,55,4,0);
    	}
     
    	/* INSTANTANEOUS RATE FUNCTION 2 */
    	static double lpm2hpm(double age) {
    	    //return exphrf(age, 2);
     
    		return unihrf(age, 9,11);
    	}
     
    	static double manufacture(double age){
     
    		double temp;//to ensure the manufacture process happening every 1 minute
    		if(Math.round(age)>age)
    		{
    		temp=age-(Math.round(age)-1); 
    		}
    	else
    		temp=age-Math.round(age);
     
     
     
    		return dethrf(temp,1);
     
    	}
     
     
     
     
     
    	/********************************************************/
    	/*  main processing loop                                */
    	/********************************************************/
     
    	public static void main(String[] args){
     
     
    	        int     kmax;    //necessary sim level in proxel tree including the initial level
    		    Proxel currproxel;
    		    double  val, z,m;
    		    int     s, tau1k;  //, tau2k;
     
    		    /* initialize the simulation */
     
    		    root[0] = null;
    		    root[1] = null;
    		    eerror=0.0;
    		    totcnt  = 0;
    		    maxccp  = 0;
    			tmax = ENDTIME;
    		    dt = DELTA;
    		    kmax=(int) (tmax/dt+1);       //add one to include the simulation at time 0
     
    		   y=new double[3][kmax+2];
     
     
     
    		    for (int k = 0; k < 3; k++) {
    		    	//..........................
    		        for (int j = 0; j < kmax+2; j++) 
    		        	y[k][j] = 0.0;
    		    }
     
    		    TAUMAX =(int)(tmax/dt+1);         //TAUMAX=kmax?
     
     
     
    		    /* set initial proxel */
    		    addproxel(HPM, 0, 0, 1.0);
     
    		    /* first loop: iteration over all kmax time steps*/
    		    for (int k = 1; k <= kmax+1; k++) {
     
     
    		        sw = 1 - sw;
     
    		        /* second loop: iterating over all proxels of a time step */
    		        while (root[1-sw] != null)
    		        {
    		            totcnt++;
    		            currproxel = getproxel();
    		            while ((currproxel.val < MINPROB) && (root[1-sw] != null)) {
    		                val=currproxel.val;
    		                eerror += val;
    		                currproxel = getproxel();
    		            }
    		            val        = currproxel.val;
    		            tau1k      = currproxel.tau1k;
    		            /*tau2k      = currproxel->tau2k;*/
    		            s          = currproxel.s;
     
    		            y[s][k-1] += val;
     
    		            /* create child proxels */
    		            switch (s) {
    		                case HPM:
    		                	z = dt*hpm2lpm(tau1k*dt);
     
    		                	if (z < 1.0) {
    			                    addproxel(LPM,       0, 0, val*z);
    			                    addproxel(HPM,  tau1k+1, 0, val*(1-z));
    		                	} else
    		                		addproxel(LPM,       0, 0, val);
    		                    break;
     
     
    		                case LPM : 
    		                	z = dt * lpm2hpm(tau1k*dt);
    		                	if (z < 1.0) {
    			                    addproxel(HPM,        0, 0, val*z);
    		    	                addproxel(LPM, tau1k+1, 0, val*(1-z));
    		                	} else 
    		                		addproxel(HPM,        0, 0, val);
    		            }
    		        }
    		    }
     
    		    System.out.printf("error = %7.5e\n", eerror); 
     
    		    System.out.printf("ccpx = %d\n", maxccp);
    		    System.out.printf("count = %d\n", totcnt);
     
    		    plotsolution(kmax);
    		    //return 0;	
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    	}
     
     
     
     
     
     
    }
    Last edited by deathlypest; June 5th, 2012 at 10:24 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: a very confusing exception

    If you want help, you'll have to provide an SSCCE that demonstrates the problem- in your case, a main method containing a single printf statement with the values that cause the Exception.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    deathlypest (June 4th, 2012)

  4. #3
    Member
    Join Date
    Feb 2011
    Posts
    33
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: a very confusing exception

    Quote Originally Posted by deathlypest View Post
    Problem:
     
    public static void main(String[] args){
     
    		    /* initialize the simulation */
     
    		    eerror=0.0;
    		    totcnt  = 0;
    		   y=new double[3][kmax+2];
     
     
     
    		    for (int k = 0; k < 3; k++) {
    		    	//..........................
    		        for (int j = 0; j < kmax+2; j++) 
    		        	y[k][j] = 0.0;
    		    }
     
     
    		    /* first loop: iteration over all kmax time steps*/
    		    for (int k = 1; k <= kmax+1; k++) {
     
     
    		        /* second loop: iterating over all proxels of a time step */
    		        while (root[1-sw] != null)
    		        {
    		            y[s][k-1] += val;
     
    .....................................
     
    		    System.out.printf("error = %7.5e\n", eerror); 
     
    		    System.out.printf("ccpx = %d\n", maxccp);
    		    System.out.printf("count = %d\n", totcnt);
    		    System.out.printf("count = %d\n", defective);
     
    		    plotsolution(kmax);
    		    //return 0;

    The line 517 is the sentence y[s][k-1] += val; which placed in the second loop.
    I have tested the exception causing codes in a simplified test program.It runs ok.

    Looks to me like your while loop is missing a closing bracket...


    All intelligent thoughts have already been thought;
    what is necessary is only to try to think them again.



  5. The Following User Says Thank You to WhiteSoup12 For This Useful Post:

    deathlypest (June 5th, 2012)

  6. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    Which of the 4 printf statements that you posted gives the error?
    Could you change the posted code so it has only one printf that has the problem?

    Make a simple complete program that will compile, execute and show the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    deathlypest (June 5th, 2012)

  8. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    actually all these four print methods in main method call no exception,they just can not print out

    the exception message lies in these two lines where I have already showed:

    y[s][k-1] += val;(line 517)
    System.out.printf("%7.5f \t %7.5e \t %7.5e \n", k*dt, y[0][k], y[2][k]);(line 195)

    when I change the position of the codes a little.Sometimes the exception line number points to a comment even.
    Last edited by deathlypest; June 5th, 2012 at 04:43 AM.

  9. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    I am sorry.this may be a copy problem.There is no compile error in my program.Thank you

  10. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    The problem in post#1 was a runtime exception NOT a compiler problem. If you are still getting that exception and want help with it, you need to post a complete program that compiles, executes and shows the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #8
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    still looking for help.I have uploaded the whole program from which you can get the same exception information.

  12. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    Can you make a small simple program that compiles, executes and shows the problem? Copy the part that is the problem into a small program, don't post the whole program (over 500+ lines) that is mostly not part of the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #10
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    I have cutted my program a little shorter.What really matters to the exception here is the block where exists a plotsolution function,some relative variables declaration and the system.out.printf() in the main method.In all about 20 lines,others can be omitted.

    Thank you very much

  14. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    Can you post the full contents of the screen from when you execute the program?

    Where is the small program for testing? What number post is it in? I would expect the program to be less than 30 lines of code.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #12
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    the full screen is
    STEP 100
    Size of tree 102
     
    STEP 200
    Size of tree 199
     
    STEP 300
    Size of tree 279
     
    STEP 400
    Size of tree 268
     
    STEP 500
    Size of tree 283
     
    STEP 600
    Size of tree 278
     
    STEP 700
    Size of tree 282
     
    STEP 800
    Size of tree 282
     
    STEP 900
    Size of tree 279
     
    STEP 1000
    Size of tree 282
     
    STEP 1100
    Size of tree 281
     
    STEP 1200
    Size of tree 281
     
    STEP 1300
    Size of tree 282
     
    STEP 1400
    Size of tree 281
     
    STEP 1500
    Size of tree 282
     
    STEP 1600
    Size of tree 281
     
    STEP 1700
    Size of tree 281
     
    STEP 1800
    Size of tree 282
     
    STEP 1900
    Size of tree 281
     
    STEP 2000
    Size of tree 281
    ccpx = 523237
    count = 521134
     
     
    Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'l'
    	at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    	at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    	at java.util.Formatter.parse(Unknown Source)
    	at java.util.Formatter.format(Unknown Source)
    	at java.io.PrintStream.format(Unknown Source)
    	at java.io.PrintStream.printf(Unknown Source)
    	at proxel.MTProxel.plotsolution(MTProxel.java:195)
    	at proxel.MTProxel.main(MTProxel.java:517)

    the small program ensures the syntical correctness of sentence:
    for(int k=0; k<=kmax; k++)
    {
    System.out.printf("%7.5f \t %7.5e \t %7.5e \n", k*dt, y[0][k], y[2][k]);

    }

    is that possible just focus on the lines that cause exceptions,I don not understand the exception.
    What means Conversion = 'l' I have not used this symbol in format output .
    Last edited by deathlypest; June 5th, 2012 at 02:28 PM.

  16. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    Try debugging the code by adding a call to println() just before the call to printf() and have it print out the values of the variables used in the printf() method call. That will show what the values are that are being formatted.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    Are you working with a different program? I don't see what this line would output in what you posted:
    System.out.printf("error = %7.5e\n", eerror);
    If you don't understand my answer, don't ignore it, ask a question.

  18. #15
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    Quote Originally Posted by Norm View Post
    Are you working with a different program? I don't see what this line would output in what you posted:
    System.out.printf("error = %7.5e\n", eerror);
    That is just one of things that confused me.I am also not able to get the output of variable eerror in my program.And when I try to debug it,every time "source not found" will be showed.But the codes after it works well.I will try debug once more with println
    Last edited by deathlypest; June 6th, 2012 at 06:03 AM.

  19. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    If you work with one source and post another source here there is no way anyone can help you find and fix the problem.

    What prints out when you add the println just before the printf where the error occurs?
    If you don't understand my answer, don't ignore it, ask a question.

  20. #17
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    they are just the same! but cutted from 500+ to 400+ by eliminating some branch codes.after using println,error still does not output
    Last edited by deathlypest; June 6th, 2012 at 07:05 AM.

  21. #18
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    I know it does not seem to make sense.But it just the problem

  22. #19
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    If you have time trying to execute the program I gave,you should get the same result just like me

  23. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    What prints out when you add the println just before the printf where the error occurs?

    I do NOT get any errors with the code you posted. Since it is different code from what you are using, its a waste of time when the code is NOT identical.
    Last edited by Norm; June 6th, 2012 at 07:12 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #21
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    really appreciate for your time.
    I put the original codes upon here.By cutting the program to a relative simple one having caused some changes which influenced the error.
    If you have to execute the following program,you will just get what I can see.Sorry for that,I am a newbee for asking question like that in forum.it is really not so easy.

    package proxel;
     
    import java.util.LinkedList;
    import java.util.List;
     
     
    class Proxel {
     
        int     id;                  /* unique proxel id for searching    */
        int     s;                   /* discrete state of SPN             */
        int     tau1k;               /* first supplementary variable      */
        int     tau2k;               /* second supplementary variable     */
        double  val;                 /* proxel probability                */
        Proxel left, right;         /* reference to child proxels in tree */
     
    }
     
     
     
     
    public class MTProxel {
     
    	static  double[][]  y;                        /* vectors for storing solution      */
    	static double  tmax  ;                        /* maximum simulation time           */
    	static int     TAUMAX;                        /*the largest possible aging time    */
     
    	static  int     totcnt;                        /* counts total proxels processed    */
    	static  int     maxccp;                        /* counts max # concurrent proxels   */
    	static  int     ccpcnt ;                       /* counts concurrent proxels         */
     
    	static Proxel[] root=new Proxel[2];           /* trees for organizing proxels      */
     
    	static List<Proxel> firstfree=new LinkedList<Proxel>(); ;                     /* linked list of free proxels       */
    	static double  eerror      = 0;               /* accumulated error                 */
     
    	static int     sw         = 0;                /* switch for old and new time steps */
     
    	static int len;
    	static double dt;                             /* DELTA*/
     
     
    	final static double ENDTIME=10;
    	final static double DELTA=0.005;
    	final static double MINPROB=1.0e-12;
    	final static int HPM=        0;
    	final static int  LPM=       2;
     
    //outcome of the machine production	
    	 static double defective;
    	 static double working;
     
     
     
     
     
     
     
    	/********************************************************/
    	/*	distribution functions			                    */
    	/*	instantaneous rate functions			            */
    	/********************************************************/
     
    	/* returns weibull IRF */
     
    	static double weibullhrf(double x, double alpha, double beta, double x0) {
    	    double y;
     
    	    y = beta/alpha*Math.pow((x-x0)/alpha,beta-1);
    	    return y;
    	}
     
     
    	/* returns deterministic IRF */
    	static double dethrf(double x, double d) {
    	    double y;
     
    	    if (Math.abs(x - d) < dt/2)
    	        y = 1.0/dt;
    	    else
    	        y = 0.0;
    	    return y;
     
    	}
     
     
    	/* returns uniform IRF */
    	public static double unihrf(double x, double a, double b) {
    	    double y;
     
    	    if ((x >= a) && (x < b))
    	        y = 1.0/(b-x);
    	    else
    	        y = 0.0;
     
    	    return y;
    	}
     
     
     
    	/********************************************************/
    	/*	output functions			                        */
    	/********************************************************/
    	/* print all proxels in tree */
    	static void printtree(Proxel p) {
    	    if (p == null)
    	        return;
    	    System.out.printf("s %d t1 %d t2 %d val %f \n",p.s,p.tau1k,p.tau2k,p.val);
    	    printtree(p.left);
    	    printtree(p.right);
    	}
     
    	/* print out complete solution */
    	static void plotsolution(int kmax) {
    		System.out.printf("\n\n");
     
    	    for(int k=0; k<=kmax; k++)
    	    { 
    	    	System.out.printf("%7.5f \t %7.5e \t %7.5e \n", k*dt, y[0][k], y[2][k]);
     
    	    }
     
    	}
     
    	/* print out a proxel */
    	static void printproxel(Proxel c) {
    	    System.out.printf("processing %2d %2d %7.5e \n", c.s, c.tau1k, c.val);
    	}
     
     
     
     
    	/********************************************************/
    	/*	proxel manipulation functions			            */
    	/********************************************************/
     
    	/* compute unique id from proxel state */
    	static int state2id(int s, int t1k, int t2k) {
    	    return(TAUMAX*(TAUMAX*s+t1k)+t2k);
    	}
     
    	/* compute size of tree */
    	static int size(Proxel p) {
    	    int sl, sr;
     
    	    if (p == null)
    	        return(0);
    	    sl = size(p.left);
    	    sr = size(p.right);
    	    return(sl+sr+1);
    	}
     
     
     
    	/* get a fresh proxel and copy data into it */
    	static Proxel insertproxel(int s, int tau1k, int tau2k, double val) {
     
    		Proxel temp;
     
    	    /* create new proxel or grab one from free list */
    	    if (firstfree.isEmpty()== true)
    	        temp = new Proxel();
    	    else {
    	    	/*temp = firstfree;
    	        firstfree = firstfree.right;*/
     
    	    	temp=((LinkedList<Proxel>) firstfree).removeFirst();
     
    	    }
    	    /* copy values */
    	    temp.id    = state2id(s, tau1k, tau2k);
    	    temp.s     = s;
    	    temp.tau1k = tau1k;
    	    temp.tau2k = tau2k;
    	    temp.val   = val;
    	    ccpcnt     += 1;
     
    	    //to count the max number of the concurrent Proxel
    	    if (maxccp < ccpcnt) {
    	        maxccp = ccpcnt;
    	        //printf("\n ccpcnt=%d",ccpcnt);
    	    }
    	    return temp;
    	}
     
     
    	/*returns a proxel from the tree*/ 
    	static Proxel getproxel()
    	{
    	    Proxel temp;
    	    Proxel old;
    	    final int LEFT = 0, RIGHT = 1;
    	    int dir=1;                 //to record it is right or left child of its parent
    	    int cont = 1;            //a mark to label if it has been already the leaf
     
    	    if (root[1-sw] == null)
    	        return null;
     
    	    temp = root[1-sw];
    	    old  = temp;
     
    	    /*move down the tree to a leaf */
    	    while (cont == 1)
    	    {
    	        /* go right */
    	        if ((temp.right != null) && (temp.left == null))
    	        {
    	            old  = temp;
    	            temp = temp.right;
    	            dir  = RIGHT;
    	        }
     
    	        /* go left */
    	        else if ((temp.right == null) && (temp.left != null))
    	        {
    	            old  = temp;
    	            temp = temp.left;
    	            dir  = LEFT;
    	        }
     
    	        /* choose right/left at random */
    	        else if ((temp.right != null) && (temp.left != null))
    	        {
     
    	            if (Math.random() >0.5)     // 0.5 is a random bound here,RAND_MAX/2
    	            {
    	                old  = temp;
    	                temp = temp.left;
    	                dir  = LEFT;
    	            }
    	            else
    	            {
    	                old  = temp;
    	                temp = temp.right;
    	                dir  = RIGHT;
    	            }
    	        }
     
    	        else
    	            cont = 0;
    	    }          //end while
     
    	    //remove the proxel which has been returned from the tree
    	    if (temp == root[1-sw])
    	        root[1-sw] = null;
    	    else
    	    {
    	        if (dir == RIGHT)
    	            old.right = null;
    	        else
    	            old.left = null;
    	    }
    	   /*c: old = firstfree;
    	    firstfree = temp;
    	    temp.right = old;
    	    ccpcnt -= 1;*/
     
    	    ((LinkedList<Proxel>)firstfree).addFirst(temp);
     
     
     
    	    return temp ;
    	}
     
    	/* adds a new proxel to the tree */
    	static void addproxel(int s, int tau1k, int tau2k, double val) {
    	    Proxel temp, temp2;
    	    int cont = 1,id;
     
    	    /* Alarm! TAUMAX overstepped! */
    	    if (tau1k >= TAUMAX) {
    	        //  printf(">>> %3d %3d %3d %7.5le \n", s, tau1k, val, TAUMAX);
    	        tau1k = TAUMAX - 1;
    	    }
     
     
    	    /* New tree, add root */
    	    if (root[sw] == null) {
    	        root[sw] = insertproxel(s,tau1k, tau2k, val);
    	        root[sw].left = null;
    	        root[sw].right = null;
    	        return;
    	    }
     
    	    /* compute id of new proxel */
    	    id = state2id(s,tau1k, tau2k);
     
    	    /* Locate insertion point in tree */
    	    temp = root[sw];
    	    while (cont == 1) {
    	        if ((temp.left != null) && (id < temp.id))
    	            temp = temp.left;
    	        else
    	            if ((temp.right != null) && (id > temp.id))
    	                temp = temp.right;
    	            else
    	                cont = 0;
    	    }
     
    	    /* Insert left leaf into tree */
    	    if ((temp.left == null) && (id < temp.id)) {
    	        temp2        = insertproxel(s, tau1k,tau2k, val);
    	        temp.left   = temp2;
    	        temp2.left  = null;
    	        temp2.right = null;
    	        return;
    	    }
     
    	    /* Insert right leaf into tree */
    	    if ((temp.right == null) && (id > temp.id)) {
    	        temp2        = insertproxel(s, tau1k,tau2k, val);
    	        temp.right  = temp2;
    	        temp2.left  = null;
    	        temp2.right = null;
    	        return;
    	    }
     
    	    /* Proxels have the same id, just add their vals */
    	    if (id == temp.id) {
    	        temp.val += val;
    	        return;
    	    }
    	    System.out.printf("\n\n\n!!!!!! addproxel failed !!!!!\n\n\n");
    	}
     
     
     
     
    	/********************************************************/
    	/*	model specific distribtuions	                    */
    	/********************************************************/
     
     
    	/* INSTANTANEOUS RATE FUNCTION 1 */
    	static double hpm2lpm(double age) {
    	    //return unihrf(age, 0.25, .5);
     
    	    return weibullhrf(age,55,4,0);
    	}
     
    	/* INSTANTANEOUS RATE FUNCTION 2 */
    	static double lpm2hpm(double age) {
    	    //return exphrf(age, 2);
     
    		return unihrf(age, 9,11);
    	}
     
    	static double manufacture(double age){
     
    		double temp;//to ensure the manufacture process happening every 1 minute
    		if(Math.round(age)>age)
    		{
    		temp=age-(Math.round(age)-1); 
    		}
    	else
    		temp=age-Math.round(age);
     
     
     
    		return dethrf(temp,1);
     
    	}
     
     
     
     
     
    	/********************************************************/
    	/*  main processing loop                                */
    	/********************************************************/
     
    	public static void main(String[] args){
     
     
    	        int     kmax;    //necessary sim level in proxel tree including the initial level
    		    Proxel currproxel;
    		    double  val, z,m;
    		    int     s, tau1k;  //, tau2k;
     
    		    /* initialize the simulation */
     
    		    root[0] = null;
    		    root[1] = null;
    		    eerror=0.0;
    		    totcnt  = 0;
    		    maxccp  = 0;
    			tmax = ENDTIME;
    		    dt = DELTA;
    		    kmax=(int) (tmax/dt+1);       //add one to include the simulation at time 0
     
    		   y=new double[3][kmax+2];
     
     
     
    		    for (int k = 0; k < 3; k++) {
    		    	//..........................
    		        for (int j = 0; j < kmax+2; j++) 
    		        	y[k][j] = 0.0;
    		    }
     
    		    TAUMAX =(int)(tmax/dt+1);         //TAUMAX=kmax?
     
    		    defective=0.0;
    		    working=0.0;
     
    		    /* set initial proxel */
    		    addproxel(HPM, 0, 0, 1.0);
     
    		    /* first loop: iteration over all kmax time steps*/
    		    for (int k = 1; k <= kmax+1; k++) {
     
    		        //if(k==79 || k==78) printtree(root[sw]);
     
    		         //printf("\nSTEP %d\n",k);
    		        /* current model time is k*dt */
     
    		        /* print progress information */
    		        if (k%100==0)  {
    		            System.out.printf("\nSTEP %d\n",k);
    		            System.out.printf("Size of tree %d\n",size(root[sw]));
    		        }
     
    		        sw = 1 - sw;
     
    		        /* second loop: iterating over all proxels of a time step */
    		        while (root[1-sw] != null)
    		        {
    		            totcnt++;
    		            currproxel = getproxel();
    		            while ((currproxel.val < MINPROB) && (root[1-sw] != null)) {
    		                val=currproxel.val;
    		                eerror += val;
    		                currproxel = getproxel();
    		            }
    		            val        = currproxel.val;
    		            tau1k      = currproxel.tau1k;
    		            /*tau2k      = currproxel->tau2k;*/
    		            s          = currproxel.s;
     
    		            y[s][k-1] += val;
     
    		            /* create child proxels */
    		            switch (s) {
    		                case HPM:
    		                	z = dt*hpm2lpm(tau1k*dt);
    		                	m=dt*manufacture(tau1k*dt);
     
    		                	if(m==1){
    		                		defective+=0.05;//expected value of the products
    		                		working+=0.95;
     
    		                	}
    		                	if (z < 1.0) {
    			                    addproxel(LPM,       0, 0, val*z);
    			                    addproxel(HPM,  tau1k+1, 0, val*(1-z));
    		                	} else
    		                		addproxel(LPM,       0, 0, val);
    		                    break;
     
     
    		                case LPM : 
    		                	z = dt * lpm2hpm(tau1k*dt);
                                m=dt*manufacture(tau1k*dt);
     
    		                	if(m==1){
    		                		defective+=0.2;
    		                		working+=0.8;
     
    		                	}
    		                	if (z < 1.0) {
    			                    addproxel(HPM,        0, 0, val*z);
    		    	                addproxel(LPM, tau1k+1, 0, val*(1-z));
    		                	} else 
    		                		addproxel(HPM,        0, 0, val);
    		            }
    		        }
    		    }
     
    		    System.out.printf("error = %7.5e\n", eerror); 
     
    		    System.out.printf("ccpx = %d\n", maxccp);
    		    System.out.printf("count = %d\n", totcnt);
    		    System.out.printf("count = %d\n", defective);
     
    		    plotsolution(kmax);
    		    //return 0;	
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    	}
     
     
     
     
     
     
    }

    Also from shortening the codes I have got some ideas about debugging.But the problem is still there,it will be much better if you can give a hand.

  25. #22
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    there is no use by putting println

  26. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    What prints out when you add the println just before the printf where the error occurs?
    there is no use by putting println
    If you do not want to do the above then I can not help you any more. You need to add the printlns to show what the data is before the printf has the exception

    better if you can give a hand.
    Add the println, execute the program and post the output here. I need the output from your program to see what is happening.
    If you don't understand my answer, don't ignore it, ask a question.

  27. #24
    Junior Member
    Join Date
    Jun 2012
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: a very confusing exception

    Oh god.Do you mean put "System.out.println(k*dt+ y[0][k]+ y[2][k]);" before the exception calling line and "System.out.println( eerror);"

    Of course,I have done it.But it does not make any changes to the output results.If I can get the output there will not be any confusion. I can even not get the value from variables in debugging.It seems not to be a format problem.Or?
    Last edited by deathlypest; June 6th, 2012 at 08:25 AM.

  28. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a very confusing exception

    Change the println to this so it prints the three values and not their sum:
    System.out.println(k*dt+ " " + y[0][k]+" " + y[2][k]);

    Execute the code, copy the output and paste it here.

    I can even not get the data from debugging.
    What does that mean? Are you putting the println in the correct place?
    It should be before the line where the exception occurs.
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 11
    Last Post: April 5th, 2012, 08:34 PM
  2. What is Abstraction?The Confusing Concept Simplified
    By rainbow9 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 14th, 2011, 11:43 PM
  3. [SOLVED] ArrayList object's elements confusing??? doesnt replace the elements? set() method?
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 21st, 2011, 01:20 PM
  4. Button help, confusing error.
    By camboy8 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 17th, 2010, 10:25 PM
  5. While (logical confusing output)
    By chronoz13 in forum Loops & Control Statements
    Replies: 4
    Last Post: December 20th, 2009, 01:17 AM