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 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 63

Thread: Writing Path name to configure Java

  1. #26
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by PhHein View Post
    Because there's an order what the compiler checks. First all required dependencies are checked, and if those are ok, the actual code is compiled. In this case the compiler didn't get to that point.
    Ok, thanks. I'd prefer to find why I can't get the Ptolemy.plot package to be found before I worry about getting the code to actually work. I don't know what else to try though - everything you have said makes sense, I just cannot get it to work.

  2. #27
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Writing Path name to configure Java

    Copy my example from reply #19 exactly in your system and make it work.

    If it doesn't, copy your input and output here.

  3. #28
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Input:
    package ph;
     
    import ptolemy.plot.*;
     
    public class PLTest{
    	public static void main(String[] args){
    		System.out.println("Jap");
    		Plot p = new Plot();
    		p.setName("phh");
    		System.out.println(p.getName());
    	}
    }

    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

  4. #29
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Writing Path name to configure Java

    Then the jar file is not in that directory: C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/

  5. #30
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by PhHein View Post
    Then the jar file is not in that directory: C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/
    I am not sure I understand. I see a plot 'executible JAR file' in the file folder plot but I also see the file folder 'plotml' in 'plot' which contains the 'executible JAR file' plotml

  6. #31
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Writing Path name to configure Java

    Dammit, post the complete path to plot.jar. I bet it is not: C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/

  7. #32
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by PhHein View Post
    Dammit, post the complete path to plot.jar. I bet it is not: C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/
    No, it is C:/ProgramFiles/Java/jdk1.7.0_21/ptplot5.8/ptolemy/plot/plot.jar

  8. #33
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Writing Path name to configure Java

    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.

  9. #34
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by PhHein View Post
    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.

  10. #35
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    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?

  11. #36
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    I fixed the code
    Please post the modified version of the code any time you make changes

  12. #37
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Hi jps,
    Quote Originally Posted by jps View Post
    Please post the modified version of the code any time you make changes
    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.

  13. #38
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Writing Path name to configure Java

    the posted code is not the problem

    Where is the Plot and PlotFrame class?

    It is much easier to assist with a SSCCE

  14. #39
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post

    Where is the Plot and PlotFrame class?
    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.

  15. #40
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Writing Path name to configure Java

    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.

  16. #41
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    It sounds like an infinite loop or the thread is blocked.
    Can you see anywhere in my code where I created an infinite loop?

  17. #42
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    Can you see anywhere in my code where I created an infinite loop?
    There is only one loop in the posted code, use a println and test it

  18. #43
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    There is only one loop in the posted code, use a println and test it
    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?

  19. #44
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    When I put in a println statement
    Always include the modified version of the code when changes are made.

    Quote Originally Posted by CAF View Post
    At the end of the code, I put the statement 'System.exit(0);' which ends the infinite loop
    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.

    Quote Originally Posted by CAF View Post
    why do I have an infinite loop
    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).

  20. #45
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    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

  21. #46
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Writing Path name to configure Java

    setting the frame visible 500 times is a bit silly, no?

  22. #47
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by PhHein View Post
    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.

  23. #48
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Writing Path name to configure Java

    When you try to compile what? How could something appear when compiling?

  24. #49
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by PhHein View Post
    When you try to compile what? How could something appear when compiling?
    Ah you're too quick! I edited my post when I reread it. See above

  25. #50
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    The only thing I have changed
    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:
    Quote Originally Posted by CAF View Post
    System.exit(0) statements at the very end
    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 ---

    Quote Originally Posted by CAF View Post
    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.
    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)

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. How to configure context.xml in netbeans IDE?
    By tangara in forum Java IDEs
    Replies: 1
    Last Post: January 5th, 2012, 11:18 PM
  2. How to convert local path drive to UNC path
    By krisswift in forum Object Oriented Programming
    Replies: 2
    Last Post: November 17th, 2011, 08:40 AM
  3. Relative path issue with Context path struts
    By chinnu in forum Web Frameworks
    Replies: 1
    Last Post: March 31st, 2011, 10:17 AM
  4. TOMCAT CONFIGURE
    By jugalrockz in forum Java Servlet
    Replies: 1
    Last Post: January 5th, 2011, 07:09 PM
  5. how to get full path name from realtive path
    By priyanka3006 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: August 10th, 2009, 04:28 AM