• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Going out of my mind

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic