Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Problems with instantiating a File object from text.txt put in at args[0]

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
This should be really basic, Just passing one file (in my project folder, triple checked that) into command line at args[0]

receiving error

The line in question is File f.... Any ideas? Suggestions?



Sincerely Stuck,
J
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You obviously didn't provide any command line arguments to the Java program.
 
Jai Gates
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is I did everything that would indicate that I did. Went into Netbeans project properties, selected it as my main class, selected myText.txt as my only argument, and pressed ok.

Checked a few times to make sure the text name is correct and the text file is in project folder so don't have to specify pathname in argument.
 
Jai Gates
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even tried specifying absolute path in argument. Will try from command line too to see if something having to do with netbeans.
 
Jai Gates
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened:

I got a 0 return in Netbeans for S.O.P(args.length); and a 1 return at command line for S.O.P(for args.length);



So it was being passed in at command line and not at Netbeans. Strange.


Finally figured out that right clicking and running one class in a project, *even* if others not connected in any way, does not give you the same results as right clicking and running the main project.

When I did the latter, I got the a 1 output in Netbeans.

*whew* ...at this rate...

Thanks.

-J
 
Rob Spoor
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm glad you found the answer
 
Marshal
Posts: 79635
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not convinced that using NetBeans or return values from exit are the best way to program if you are a beginner.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic