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.
Copy my example from reply #19 exactly in your system and make it work.
If it doesn't, copy your input and output here.
Input:
And in the command terminal: javac -classpath .;C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/plot.jar PLTest.java
3 errors: Cannot find ptolemy.plot package
and two more errors - cannot find symbol Plot
Then the jar file is not in that directory: C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/
Dammit, post the complete path to plot.jar. I bet it is not: C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/
Ok, last try. Create a new folder c:/plot and copy the plot.jar into it and try again with javac -classpath .;c:/plot/plot.jar PLTest.java. If that doesn't work I'm lost.
That didn't work either. I'll try again later, although I would not be sure what else to try. I did not think it would take so long to just configure this package and all of the tutorials I have looked at are too vague for my tastes. Many thanks for all your efforts though, I appreciate it.
Hi PhHein,
I managed to finally get the code to compile and I fixed the code to correct the remaining errors as you anticipated. I went to run it using the command:
java -cp .;"C:\Program Files\Java....\plot.jar" Edisc and the following message appears: (I have typed what it says since I don't know how to copy from the terminal)
Exception in thread "main" java.lang.NoClassDefFoundError: ptolemy/util/RunnableExceptionCatcher
at ptolemy.plot.Plot.addPoint(Plot.java:275)
at Edisc.main(Edisc.java:38)
Caused by java.lang.ClassNotFoundException: ptolemy.util.RunnableExceptionCatcher
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLocader$1.run(Unknown Source)
.... (some more statements similar to the above) then ...2 more.
I can't make any sense out of that - so given that everything compiled fine, there must be an error somewhere during runtime.
Have you any thoughts?
Hi jps,
Yes, sure here it is:
import java.io.Console; import java.io.*; import java.lang.Math; import java.lang.Boolean; import ptolemy.plot.*; public class Edisc { public static void main (String args[]) { Console myConsole = System.console(); Plot disc = new Plot(); disc.setTitle("Graph of the axial E field from a charged disc"); disc.setXLabel("distance along z"); disc.setYLabel("E field"); PlotFrame myFrame = new PlotFrame("E vs z", disc); myFrame.setSize(800,600); int dataSet = 0; double q = 6.0e-9; double R = 10; double eps = 8.85e-12; int points = 100; double E[] = new double[points]; double z[] = new double[points]; for(int i = 0; i < (points-1); i++) { z[i] = (100*(int)i/points); double Eqn = q/((2*(Math.PI)*eps*(Math.pow(R,2)))*(1 - z[i]/(Math.sqrt((Math.pow(R,2)) + (Math.pow(z[i],2)))))); disc.addPoint(dataSet, z[i], Eqn, true); myFrame.setVisible(true); } } }
This version of the code compiled, it is just at runtime I get errors. (I did not know that at runtime you could possibly have more errors, so I am a bit mystified). Thanks.
the posted code is not the problem
Where is the Plot and PlotFrame class?
It is much easier to assist with a SSCCE
Yes, I forgot to reference the other jar file - it now works albeit my graph looks a bit strange (but I should be able to fix this via changing the plotframe size etc..) Everytime I run though and when it produces the graph, I lose control of the command terminal, that is I cannot type anything in it anymore. This means everytime I run (after making changes), I must first get to correct directory, then compile then run. This is tedious. Is there a way to regain access of the terminal? Thanks again.
It sounds like an infinite loop or the thread is blocked.
This is where a debugger comes in handy, but it can still be done without one. Either way, you will just have to figure out where the program execution stops (for what ever reason it may be).
I just want to mention also, as a side note on errors.
Treat the program like it has exactly one error at all times. Until you correct the first error listed, there are no other errors. Every time you attempt to compile, and eventually run, stop and fix the "only" error there is and try to compile and run again. Compile and run often.
When I put in a println statement, I have the contents of that statement displayed a large number of times in the command terminal, so I think that the loop is going over and over again. Is there a way to fix this?
EDIT: At the end of the code, I put the statement 'System.exit(0);' which ends the infinite loop and I can regain access of the terminal. I was wondering though, why do I have an infinite loop and where can I fix it in the code?
Always include the modified version of the code when changes are made.
infinite loops do not end, that is what is so special about them. Again, post the code showing the changes so we can see what is happening.
Are you sure you do? Include the index counter of the loop in your println to see how many times it does run since you are using such a large number during testing (unless you would like to count them all).
Here is the updated code:
import java.io.Console; import java.io.*; import java.lang.Math; import java.lang.Boolean; import ptolemy.plot.*; public class Edisc1 { public static void main (String args[]) { Console myConsole = System.console(); Plot disc = new Plot(); disc.setTitle("Graph of the axial E field from a charged disc"); disc.setXLabel("distance along z"); disc.setYLabel("E field"); PlotFrame myFrame = new PlotFrame("E vs z", disc); myFrame.setSize(10,20); int dataSet = 0; double q = 6.0e-6; double R = 10; double eps = 8.85e-12; int points = 500; double E[] = new double[points]; double z[] = new double[points]; for(int i = 0; i < (points-1); i++) { z[i] = (100*(int)i/points); double Eqn = (q/((2*(Math.PI)*eps*(Math.pow(R,2))))*(1 - (z[i]/(Math.sqrt((Math.pow(R,2)) + (Math.pow(z[i],2))))))); disc.addPoint(dataSet, z[i], Eqn, true); System.out.println("Graph created"); myFrame.setVisible(true); } System.exit(0); } }
The only thing I have changed since last time is the insertion of the println and System.exit(0) statements at the very end
setting the frame visible 500 times is a bit silly, no?
I thought the 500 I set was the number of points that would be plotted on the graph (obviously this is not the case). For some reason, when I run the program now, the graph instantaneously appears then dissapears. Any ideas why this would be the case?
Also, the number of times 'Graph created' appears seems to be proportional to what I set int points = ... to be. I don't understand this either.
When you try to compile what? How could something appear when compiling?
It may seem simple and unimportant from your seat, but from the chair where your screen is not visible, it is important to post the code any time any change is made to the syntax. "Always" post the modified code so we can see what changed where. See below:
The fact that the System.exit was placed OUTSIDE the loop, means that the loop is NOT an infinite loop, and that it is exiting as expected.
--- Update ---
Every line of code from:
for(int i = 0; i < (points-1); i++) {
all the way down to the next:
}
will be executed every time the loop runs. In the posted code that would include the 5 lines following the for statement, which includes the println, and the setVisible(true).
The system.exit is outside the loop and is only executed once, after the loop exits. This is the place where you would put things that should only happen once, after the loop exits. (like the set visible)