Results 1 to 7 of 7
  1. #1
    vouke is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Default Java DB problems!

    Hey I haven't done Java in 2 years so I can't remember much,
    This is my java program and it's throwing me some errors saying "illegal start of expression" this is affecting both submenu options (getSubmenuMFromUser & getSubmenuBFromUser)
    Other errors are present as well, but that's as a result of the main error.
    Java Code:
    public static String getMenuChoiceFromUser()
    	{
    		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
          	String ans = "";
          	try
          	{ while ( ans.length() == 0 ) {	
    			System.out.println(printBars);
    			System.out.println(printBarsStart+" >>> Enter your option <<<        "+printBarsEnd);
    			System.out.println(printBarsStart+" 1) Exit to end                   "+printBarsEnd);
    			System.out.println(printBarsStart+" 2) Display All Magazines         "+printBarsEnd);
    			System.out.println(printBarsStart+" 3) Search For Magazines          "+printBarsEnd);
    			System.out.println(printBarsStart+" 4) Display All Books          	 "+printBarsEnd);
    			System.out.println(printBarsStart+" 5) Display For Books   			 "+printBarsEnd);										
    			System.out.println(printBars);
    			System.out.println(printLine);
    			ans = br.readLine();
                if ( ans.length() == 0 ) 
                System.out.print("Nothing entered: ");
    		   }
          	} catch (java.io.IOException e) {
            	System.out.println("Could not read response");	
            }
            return ans;
    	} // show main menu for user
    
    	public void showMenu(){
           String ans = "";
           do{
    			banner();
    			response=getMenuChoiceFromUser();
    
    			if( response.substring(0,1).equals("1")){
    				
                }
    			if( response.substring(0,1).equals("2")){
    				//showDeletedTeachers();
    			} 
               if( response.substring(0,1).equals("3")){
    				getSubmenuMFromUser();
               }
               if( response.substring(0,1).equals("4")){
                   //deleteTeacher();
               }
               if( response.substring(0,1).equals("5")){
                   getSubmenuBFromUser();
               }
    		}
    	}
    	
    		public static String getSubmenuMFromUser
    	{
    		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
          	String ans = "";
          	try
          	{ while ( ans.length() == 0 ) {	
    			System.out.println(printBars);
    			System.out.println(printBarsStart+" >>> Enter your option <<<        "+printBarsEnd);
    			System.out.println(printBarsStart+" 1) Exit to end                   "+printBarsEnd);
    			System.out.println(printBarsStart+" 3.1) Select Magazines Using Name "+printBarsEnd);
    			System.out.println(printBarsStart+" 3.2) Select Magazines Using Type "+printBarsEnd);
    			System.out.println(printBars);
    			System.out.println(printLine);
    			ans = br.readLine();
                if ( ans.length() == 0 ) 
                System.out.print("Nothing entered: ");
    		   }
          	} catch (java.io.IOException e) {
            	System.out.println("Could not read response");	
            }
            return ans;
    			
    	} // Show submenu choices about book search for user
    	
    	public static String getSubmenuBFromUser()
    	{
    		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
          	String ans = "";
          	try
          	{ while ( ans.length() == 0 ) {	
    			System.out.println(printBars);
    			System.out.println(printBarsStart+" >>> Enter your option <<<        "+printBarsEnd);
    			System.out.println(printBarsStart+" 1) Exit to end                   "+printBarsEnd);
    			System.out.println(printBarsStart+" 5.1) Select Books Using Name	 "+printBarsEnd);
    			System.out.println(printBarsStart+" 5.2) Select Books Using Genre	 "+printBarsEnd);
    			System.out.println(printBars);
    			System.out.println(printLine);
    			ans = br.readLine();
                if ( ans.length() == 0 ) 
                System.out.print("Nothing entered: ");
    		   }
          	} catch (java.io.IOException e) {
            	System.out.println("Could not read response");	
            }
            return ans;
    			
    	} // Show submenu choices about book search for user
    I have more code that's before the first getMenuChoiceFromUser method, but it's not needed. Do you see anything wrong with this code;

    Thank-you in advance, if the other code is needed, I'll post that too.
    Last edited by vouke; 06-02-2013 at 02:21 PM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,379
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java DB problems!

    A 'do' must end with a matching 'while( ...)' condition; also, your placement of curly brackets is terrible now and then ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    vouke is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Default Re: Java DB problems!

    Thanks Jos,

    I fixed the while condition, though now it shows an error for "missing return statement" and indicates it's a {
    I have checked each bracket several times and I don't see why I am being shown this error

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,379
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java DB problems!

    Show us the code for the method that makes your compiler whine (and that method only please).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    vouke is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Default Re: Java DB problems!

    Java Code:
    public static String showMenu(){
           String ans = "";
           do{
    			banner();
    			ans=getMenuChoiceFromUser();
    			if( ans.substring(0,1).equals("1")){
    				
                }
    			if( ans.substring(0,1).equals("2")){
    				//showDeletedTeachers();
    			} 
               if( ans.substring(0,1).equals("3")){
    				getSubmenuMFromUser();
               }
               if( ans.substring(0,1).equals("4")){
                   //deleteTeacher();
               }
               if( ans.substring(0,1).equals("5")){
                   getSubmenuBFromUser();
               }
    		}while( ans.isEmpty());
    	}

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,379
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java DB problems!

    I don't see a 'return someString;' statement anywhere, that's why the compiler is complaining.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    vouke is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Default Re: Java DB problems!

    Thanks Jos,

    You really know your java man! I just don't need a return statement, s'all good, I'll figure another away around it.

    Thank-you, God bless.

Similar Threads

  1. Java 3d problems
    By tculig in forum New To Java
    Replies: 2
    Last Post: 09-06-2011, 10:00 PM
  2. Java RPG problems
    By Nickmanzz in forum New To Java
    Replies: 13
    Last Post: 04-13-2011, 09:14 PM
  3. java problems
    By p595285902 in forum New To Java
    Replies: 6
    Last Post: 11-28-2010, 10:55 PM
  4. Replies: 2
    Last Post: 01-16-2010, 04:50 PM
  5. Java Problems
    By xonkie in forum New To Java
    Replies: 6
    Last Post: 12-03-2008, 07:14 PM

Posting Permissions

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