1

I'm trying to run the program in this link (specifically Plotter.java).in the zip file there's an instruction on how to run them but they don't work .I've read other questions on running a java file from terminal and I've applied those solutions but none worked on this fileceven though I've run other codes without any problems (java -dir or javac ). how can I run this program? also I want to run it (the plotter) in eclipse console or a GUI made in eclipse .

p.s:I havent included any code because the program has about 10 classes and also I'm new to java.

5
  • 1
    This is not enough information. What does java say when you try to run it? Commented Feb 13, 2015 at 21:27
  • this the error when I run it on eclipse Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Plotter.main(Plotter.java:278) Commented Feb 13, 2015 at 21:31
  • 1
    That would lead me to think there is a problem with the code itself. Commented Feb 13, 2015 at 21:34
  • is there anyway to fix it? because I really need to see how it works I need a program that does what this program does getting multiple expressions and graphing them Commented Feb 13, 2015 at 21:38
  • Did you carefully read the Instructions.txt file? Commented Feb 13, 2015 at 21:43

2 Answers 2

1

Given the exception you have posted, the issue is because you are not providing java with the correct arguments. The program requires at least three arguments which are doubles.

They are:

minX (the first argument)
maxX (the second argument)
frequency (the third argument).

From the instructions which come with it inside the .zip: PlotEq:

java PlotEq <min-x> <max-x> <sample-rate> <Expression>
Where:
min-x: is the minimum value of x to begin plotting
max-x: is the maximum value of x to plot up to.
sample-rate: how close points are plotted to eachother. A sample rate of 0.1 is generally acceptable, it means take a sample of the graph at 0.1, 0.2, 0.3, 0.4, etc. Basically determines how much detail to include in the plot
Expression: the equation to plot
example:
java PlotEq -5 5 0.01 "sin(x)"
plots sin(x) between x=-5 and 5, taking samples every 0.01 steps in x.

The issue is because of the missing arguments for min-x, max-x and sample-rate.

Sign up to request clarification or add additional context in comments.

5 Comments

thank you for your answer but It would be great if I could change plotter.java to run from eclipse console so it would be usable as a UI (or GUI which I know how to make them usually but I don't know how to implement them here)
If you want to run it from eclipse, next to the little "run" icon at the top, click the little down arrow. Then go down to "Run configurations". Double click on "Java Application" in the left menu. Select the project and Main class, then go to the "Arguments" tab. In there you can add the arguments in "Program arguments". E.g, just add -5 5 0.01 "sin(x)"
It works for PlotEq but doesn't work for plotter I made a text file and put x^2 in it then found the full path by dragging it to terminal and doing the configuration but it says the equation is not well-formed (this the 4th arg -10 10 0.01 "/Users/Sepehr/Desktop/arg12.txt") and then I opted out of using the optional file(-10 10 0.01 ) but then it says "insufficient arguments" what should I do now ?
Try the arguments suggested : -5 5 0.01 "sin(x)"
Plotter: java Plotter <min-x> <max-x> <sample-rate> <OPTIONAL file> See PlotEq. Please note here you do not provide a math equation in the argument. This is done through the GUI. Also you can specify a file which contains a list of equations (one on each line) to load into the program. Example: java Plotter -2 2 0.1 "c:\myequations.txt"
0

I tried to see the code, it seems you need to give double in the command line while you don't, so it tries to read empty array of args. Try to write after the name of class you execute three doubles in the command line, it should work than.

If you want to run the same in eclipse, Use menu of Eclipse: Run -> Run Configurations -> Java Application -> mouse right click -> New -> Arguments -> add some arguments you need.

And please read Instructions file carefully, it explains everything.

5 Comments

It looks like it actually requires 3 double arguments. minX, maxX, and a frequency.
thank you for your answer it works now but how can I change the code in Plotter.java so it will run in eclipse console without having to set arguments like you said ? making it like system.out.println("enter max and min of x separated by comma ") int max =nextint() and so on.
@karver jast put // before each line 278-280, and add below them: double minX = some your number; double maxX = some your number; double frequency = some your number; But you have to know what you do if you go this way. // is a comment, makes the code invisible for the compiler.
It worked ! thank you very much one more thing I want to use scanner to get these numbers and the arguments are in string how can change the string to double ? is there a method like : double minx = s.nextline.parsetoDouble(arg[0]) ?
I don't understand why you try to make things more complicated, but you have an example of parsing double from strings in the strings 278-280. You can put explicit string instead of arg[0], and if it is double in a string form, you will get your double. If not - you will get an exception. arg[0] here points to some String that is first in the list of arguments you give to your program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.