Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java IO textfile "cannot be resolved to a variable" error  RSS feed

 
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to read from a textfile but I'm getting the error mentionned in the title in line 4. I tried more or less everything (put the file name in " " with the complete path and so on but did not work out). Thanks for your help.


 
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
readFile() requires a String. What is TextProgram.txt? If you meant to pass a string literal and not a variable name, you need to surround it in double quotes.

You say that doesn't work, but you didn't tell us what exactly happens.
 
Frank Poupard
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I've though about, but it does not work either...
 
Ranch Hand
Posts: 35
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I've though about, but it does not work either...


Why? You got a different error? If yes then what is it, if no then what did you change?
 
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why do you create a new ArrayList, and then immediately discard it and replace it with another one?
 
Frank Poupard
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I solved it finally, I had to throw the exception this way in the main method :


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!