• Post Reply Bookmark Topic Watch Topic
  • New Topic

command line arguments  RSS feed

 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have another program, please see code below: any help would be appreciated.




I am getting this error when I run the program from JCreator:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at underground.main(underground.java:48)


and this command line error when I enter 11 from the edges.txt file as args[0] and I want to enter 163 from the edges.txt file as args[1] unable to attach the edges.txt file.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\carolin.CANSNACK>cd desktop\

C:\Users\carolin.CANSNACK\Desktop>cd al

C:\Users\carolin.CANSNACK\Desktop\al>javac underground.java

C:\Users\carolin.CANSNACK\Desktop\al>java underground 11
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at underground.main(underground.java:49)

C:\Users\carolin.CANSNACK\Desktop\al>





 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest adding this immediately inside main()

Somehow your command line arguments aren't getting through.
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes this worked, thanks a lot
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual usage is something like this:-I don't know how you pass command‑line arguments to JCreator.
 
Andrew Polansky
Ranch Hand
Posts: 310
18
Linux MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need two arguments:


But you are providing only one argument (11):


 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this as the results from command line after entering 2 arguments:



C:\Users\carolin.CANSNACK\Desktop\al>javac underground.java

C:\Users\carolin.CANSNACK\Desktop\al>java underground 239 268
Shortest path from South Ruislipto Upminster Bridge is [[South Ruislip, Northolt
, Greenford, Perivale, Hanger Lane, North Acton, East Acton, White City, Shepher
d's Bush (C), Holland Park, Notting Hill Gate, Queensway, Lancaster Gate, Marble
Arch, Bond Street, Green Park, Westminster, Waterloo, Bank, Liverpool Street, B
ethnal Green, Mile End, Stratford, West Ham, Plaistow, Upton Park, East Ham, Bar
king, Upney, Becontree, Dagenham Heathway, Dagenham East, Elm Park, Hornchurch,
Upminster Bridge]]

C:\Users\carolin.CANSNACK\Desktop\al>java underground 1 2
Shortest path from Acton Townto Aldgate is [[Acton Town, Turnham Green, Hammersm
ith, Barons Court, Earl's Court, Gloucester Road, South Kensington, Knightsbridg
e, Hyde Park Corner, Green Park, Westminster, Waterloo, Bank, Liverpool Street,
Aldgate], [Acton Town, Turnham Green, Hammersmith, Barons Court, Earl's Court, G
loucester Road, South Kensington, Sloane Square, Victoria, St. James's Park, Wes
tminster, Waterloo, Bank, Liverpool Street, Aldgate], [Acton Town, Turnham Green
, Hammersmith, Barons Court, Earl's Court, Gloucester Road, South Kensington, Sl
oane Square, Victoria, Green Park, Westminster, Waterloo, Bank, Liverpool Street
, Aldgate]]

C:\Users\carolin.CANSNACK\Desktop\al>
 
Andrew Polansky
Ranch Hand
Posts: 310
18
Linux MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like it's now working, isn't it?
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys.
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had 2 programs that worked fine separately, however when i combine them into one program, only the graph class runs. I am not getting any error messages so i am unsure how to proceed, any help would be appreciated.

 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you combined all the code?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!