Results 1 to 3 of 3
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Red face 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?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You probably have an extra closing bracket.
    Indent your code so you can pick up such errors easily.

  3. #3
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    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

  1. Replies: 1
    Last Post: 05-31-2009, 10:57 PM
  2. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  3. Replies: 16
    Last Post: 05-28-2009, 03:41 PM
  4. 'class' or 'interface' expected
    By denisdoherty in forum New To Java
    Replies: 23
    Last Post: 04-22-2008, 06:13 PM
  5. Replies: 9
    Last Post: 08-08-2007, 07:16 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •