• Post Reply Bookmark Topic Watch Topic
  • New Topic

Going out of my mind  RSS feed

 
Tony Braun
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Hi all

I am learning java from a book as a complete novice but have got stuck while writing a program in java that I wrote 15 years ago, which is still running in VB6.

Can anyone tell me why I am getting an error message on this sub class which I will call from the main class when required. It is self explanatory, but it asks for a semicolonon line 7 when a semicolon is already present.

Any help most appreciated.

Thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,
Welcome to CodeRanch!

Can you reply to this thread with the code giving the error?
 
Tony Braun
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne

The code that is bothering me is:



The line that throws me is:

File file = new File("testFile.txt");

It always asks for a semicolon but one is already there. It therefore will not complile, so what have I done wrong?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,
The message is misleading you. The actual problem is that the code isn't in a method.

Try putting it in:



(and then closing the method at the end of course.)
 
Campbell Ritchie
Marshal
Posts: 55788
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

I have gone back to your code and added code tags. Always use the tags: doesn't it look better. I also corrected the indentation a bit and removed some blank lines which are unnecessary. Also the comment to say you are creating a file is unnecessary and should be omitted (line 4). You can also see that on line 17/18 you appear to have a } which doesn't match a { anywhere, so your {} are unbalanaced and you won't get that code to compile.
There is a better way to create files and readers now that Java7 is here: look at this section of the Java™ Tutorials.
 
Tony Braun
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne and Campbell

Thanks for your replies. I think I can see were I am going wrong now. I probably will have to wait till I code up the FX interface when I have completed the main engine of the whole project.

In the mean time I think your suggestion Campbell, of doing more reading would be a good idea especially when it comes to creating, writing and reading files on the hard drive. I have a lot more work to do to rewrite a working program in VB6 to java 8 as I want to add more improvements to it that the basic program of 15 years.

Thanks again and you may here from me again hopefully with more easily answerable questions.

Thanks

Tony
 
Campbell Ritchie
Marshal
Posts: 55788
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a plain file writer; either wrap it in a buffered writer, or forget about the writer and use a Formatter object. Read all about it in the Java™ Tutorials about IO.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!