Results 1 to 3 of 3
- 08-26-2009, 03:21 PM #1
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
class, interface or enum expected?
W00t?!
I have no clue what its talking about and I looked it up on google without success...
Can someone tells me why it says that on line 98 (the last line)?
Heres my code:
PHP Code:/** * @(#)PhoneNumber.java * * PhoneNumber application * * @author Andreas * @version 1.00 2009/8/18 */ import static java.lang.System.out; import java.util.Scanner; //import java.io.IOException; import java.io.*; class myapp { static public String getContents(File aFile) { StringBuilder contents = new StringBuilder(); try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; //not declared within while loop while (( line = input.readLine()) != null){ contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException ex){ ex.printStackTrace(); } return contents.toString(); } static public void setContents(File aFile, String aContents) throws FileNotFoundException, IOException { if (aFile == null) { throw new IllegalArgumentException("File should not be null."); } if (!aFile.exists()) { throw new FileNotFoundException ("File does not exist: " + aFile); } if (!aFile.isFile()) { throw new IllegalArgumentException("Should not be a directory: " + aFile); } if (!aFile.canWrite()) { throw new IllegalArgumentException("File cannot be written: " + aFile); } Writer output = new BufferedWriter(new FileWriter(aFile)); try { output.write( aContents ); } finally { output.close(); } } } public class PhoneNumber { public static void main(String[] args) throws IOException { // TODO, add your application code char mykey; Scanner cont = new Scanner(System.in); char reply; do { out.println("Wellcome to Andreas PhoneNumber manager!"); out.println("Choose an option:"); out.println("a: Add contact"); out.println("b: Find contact"); out.println("c: Remove contact"); out.println("d: exit"); reply = cont.findWithinHorizon(".",0).charAt(0); } while (reply != 'a' && reply != 'b' && reply != 'c' && reply != 'd' ); if (reply == 'a'){ out.print("Name: "); String name = ""; do{ name = cont.nextLine(); String PN; }while (name.equals("")); out.print("Phonenumber: "); PN = ""; do{ PN = cont.nextLine(); }while (PN.equals("")); File phoneFile = new File("C:\\Users\\Andreas\\Desktop\\PhoneReg.txt"); myapp.setContent(phoneFile,myapp.getContent(phoneFile)+name+"\n"+PN+"\n"); } } } } //HERE it points out class, interface or enum expected, Why?
- 08-26-2009, 03:32 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You probably have an extra closing bracket.
Indent your code so you can pick up such errors easily.
- 08-26-2009, 07:54 PM #3
You have six open brackets '{' and seven close brackets '}' You need to figure out how your code is supposed to flow so you can decide where the brackets need to go.
Indenting the code will help you read through it much more clearly.
Mr. Beans
Similar Threads
-
E:\IT 215 Java Programming\GUI1.java:125: class, interface, or enum expected
By tlouvierre in forum New To JavaReplies: 1Last Post: 05-31-2009, 10:57 PM -
E:\IT 215 Java Programming\GUI1.java:125: class, interface, or enum expected
By tlouvierre in forum New To JavaReplies: 1Last Post: 05-31-2009, 02:17 PM -
E:\IT 215 Java Programming\Inventory.java:36: class, interface, or enum expected
By tlouvierre in forum Advanced JavaReplies: 16Last Post: 05-28-2009, 03:41 PM -
'class' or 'interface' expected
By denisdoherty in forum New To JavaReplies: 23Last Post: 04-22-2008, 06:13 PM -
illegal start of expression & class, interface, or enum expected
By silverq_82 in forum New To JavaReplies: 9Last Post: 08-08-2007, 07:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks