473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

illiegal start of type

153 New Member
Hi all, i am getting a coupke of compile errors with this code, any ideas - stuck on it for a good few hours now.

im getting a identifier in line 23 expected
}

and

illiegal start of type
try
^

Any help is appreciated.




Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.io.*;
  3. import java.awt.*;
  4. import java.util.*;
  5.  
  6. public class FileWriter2
  7. {
  8. String  pathName = "C:\\BlueJ\\bren.txt";
  9. File aFile = new File(pathName);
  10.  
  11.  
  12. try
  13. {
  14.  
  15. FileWriter aFileWriter = new FileWriter(aFile);
  16.  
  17. aFileWriter.write("Test");
  18. aFileWriter.close();
  19. }
  20. catch (Exception anException)
  21. {
  22. System.out.println("error :" + anException)
  23. }
  24. }
  25.  
Aug 6 '08 #1
12 1296
BigDaddyLH
1,216 Recognized Expert Top Contributor
Don't forget that code has to go into methods -- you forgot to define any methods, for example, a main method.
Aug 6 '08 #2
brendanmcdonagh
153 New Member
put it in a main maethod and now i m getting five errors - including it doesn't find symbol: method close and write.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3.  
  4.  
  5. public class FileWriter2
  6. {
  7. public static void main(String[] args)
  8. {
  9. String  pathName = "C:\\BlueJ\\bren.txt";
  10. File aFile = new File(pathName);
  11.  
  12.  
  13. try
  14. {
  15.  
  16. FileWriter aFileWriter = new FileWriter(aFile);
  17.  
  18. aFileWriter.write("Test");
  19. aFileWriter.close();
  20. }
  21. catch (Exception anException)
  22. {
  23. System.out.println("error :" + anException);
  24. }
  25. }
  26. }
Aug 6 '08 #3
JosAH
11,448 Recognized Expert MVP
You're not showing us the code you fed to your compiler.

kind regards,

Jos
Aug 7 '08 #4
brendanmcdonagh
153 New Member
javac FileWriter2.java
Aug 7 '08 #5
JosAH
11,448 Recognized Expert MVP
javac FileWriter2.java
That's not what I mean; your code in reply #3 compiles fine for me so I was a bit
surprised that compilation failed in your case.

kind regards,

Jos
Aug 7 '08 #6
brendanmcdonagh
153 New Member
Glad to hear what im doing is right, but why won't it compile??

I have dona a print screen on cmd errors after javac FileWriter222.java if anyone has the time to have a look but don't know how to attach file
Aug 7 '08 #7
JosAH
11,448 Recognized Expert MVP
Glad to hear what im doing is right, but why won't it compile??

I have dona a print screen on cmd errors after javac FileWriter222.java if anyone has the time to have a look but don't know how to attach file
Run it again, redirect the compiler's output streams to a file and copy/paste the
content to a new message; I'm sort of curious why that code won't compile ...

kind regards,

Jos
Aug 7 '08 #8
BigDaddyLH
1,216 Recognized Expert Top Contributor
<adjusting mindreader's turban/>
Did you earlier define a FileWriter.java? If so, the compiler is confusing it with java.io.FileWriter. Delete both your FileWriter.java and FileWriter.class.
Aug 7 '08 #9
brendanmcdonagh
153 New Member
<adjusting mindreader's turban/>
Did you earlier define a FileWriter.java? If so, the compiler is confusing it with java.io.FileWriter. Delete both your FileWriter.java and FileWriter.class.

Yes!!

No i get a noclassdeffounderror exception in thread main - but ill prob be able to work that out unless someone can see it quickly - reply 3
Aug 7 '08 #10
BigDaddyLH
1,216 Recognized Expert Top Contributor
Yes!!

No i get a noclassdeffounderror exception in thread main - but ill prob be able to work that out unless someone can see it quickly - reply 3

it's hard to see errors when the code we have has none ;-(
Aug 7 '08 #11
JosAH
11,448 Recognized Expert MVP
it's hard to see errors when the code we have has none ;-(
Yep, also see reply #6; the OP's question is quite obscure and sloppy; there are
external conditions here that are neither realized nor mentioned by the OP. We
have to dust off our crystal balls ...

kind regards,

Jos
Aug 7 '08 #12
brendanmcdonagh
153 New Member
Sorry guys,

Because (as someone suggested) I had similar named files in directory when i type javac i got earlier mentioned errors, i deleted these files and this enable compilation. the runtime error was my mistake but thank you so much for taking the time to help me:)
Aug 7 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeff Reed | last post by:
I am experiencing the the problem outlined the below. Unfortunately, I am using WinXP and I not sure if I can apply the solution due to lack of security control Any feed back would be apreciated ...
16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
9
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.