Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

simple question, drawing a blank  RSS feed

 
Eric Gertge
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not real sure what the problem is, but i get

java.lang.ArrayIndexOutOfBoundsException: 0
at Recur.main(Recur.java:7)
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

when i try to run this program.

class Recur
{
public static void main(String args[])
{
int N = Integer.parseInt(args[0]);

// Compute a sum of alternating sign series from 1 to N iteratively
System.out.print("Sum, Iterative (N = " + N + ") = ");


// Compute a sum of alternating sign series from 1 to N recursively
System.out.print("Sum, Recursive (N = " + N + ") = ");


}// EndClass Recur

I havent put in the methods yet, but why does it not like
int N = Integer.parseInt(args[0]);

thanks for any help
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you pass any command line arguments? You tried to acces args[0], i.e. the first command line argument. However, your program beleives there to not be a first command line argument to access.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as the exception says, the args array doesn't have an element of index 0 - with other words, it's empty.
 
Eric Gertge
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess im trying to do this differently than i have always done it. I have always used jGrasp to write, compile, and test programs. Im not real sure how to do it using the command prompt.

i figured that out kindof. it gives me the error
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main

it compiles fine in jGrasp though.
any advice for me?

UPDATE: I figured it out. MD-DOS is a pain compared to doing things in jGrasp. Why doesnt everyone just use jGrasp? thanks for you help
[ August 29, 2004: Message edited by: Eric Gertge ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Eric!

At first, I really didn't enjoy using the command prompt to do things, either. Once I figured out the way things work, it wasn't that bad, really.

The main reason I see for figuring out using the command prompt is to build a better understanding for how things work. That understanding can come in handy when learning to use new tools and troubleshooting some unexpected problems.
 
Eric Gertge
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so what do you guys use to write the code? I used jGRASP because i like the layout, the different colors of reserved words, comments, etc. its what i did all last year. I think it would be wierd to write code in notepad or something like that. it is also easy to compile real quick and test out. I changed a small portion of the code so i could test it out in jGRASP while i was writing the methods, then changed it back and performed my final test with the command prompt. the final program was one that found the summation of 1-2+3-4+.....N.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Netbeans 3.6 at the moment, but it seems to me that Ranchers' IDE of choice is Eclipse (judging by the volume of traffic in the IDEs forum). I've also used JBuilder, which isn't bad, and Oracle's JDeveloper, which isn't great.

If you're a beginner I wouldn't recommend an IDE straight away. Too much hand-holding prevents you from building a solid understanding of the underlying processes.

Syntax highlighting is very useful; it increases productivity and helps avoid silly mistakes. That rules notepad out. I also think that being able to compile and run at the push of a button is a good idea, but you should ideally set your classpath and directory structure as you would without integration. I can't really recommend anything, however. Textpad, maybe?

Personally, I've never even heard of jGRASP.

Jules
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're curious about what tools folks are using, I'd suggest moseying on over to the IDEs and Other Tools forum.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
If you're curious about what tools folks are using, I'd suggest moseying on over to the IDEs and Other Tools forum.


But *please* *do a search* before asking question such as "what is your favorite IDE" - that's been discussed ad nauseam...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!