Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to fix my code?

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to fix my code?

    I have a problem, can anybody help? The line public void putWords () throws IOException { shows that there are some mistakes:
    Multiple markers at this line
    - Syntax error, insert ";" to complete
    LocalVariableDeclarationStatement
    - Syntax error, insert "[ ]" to complete Dimension
    - Illegal modifier for parameter putWords; only final is permitted
    - void[] is an invalid type
    - Syntax error on token "putWords", AnnotationName expected after
    this token

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Scanner;
     
    public class Dictionary {
    	// Локальный словарь
        private final HashMap<String, String> dictMap = new HashMap<>();
     
        // Getter локального словаря
        public HashMap<String, String> getDictMap(){
            return dictMap;
        }
     
     
        public void loadDictionary(File dictionary) throws FileNotFoundException {
            Scanner scanner = new Scanner(dictionary);
            String en = "";
            String ukr = "";
            String line;
     
            while(scanner.hasNext()){
                line = scanner.nextLine();
                en = line.substring(0,line.indexOf(" ")); 
     
                ukr = line.substring(line.indexOf(" ") + 1);
     
                dictMap.put(en,ukr);
            }
        }
     
     
        public void showEnDictionary(){
     
            for (Map.Entry<String, String> pair : dictMap.entrySet()) {
                System.out.println(pair.getKey() + " - " + pair.getValue());
            }
     
        }
     
        public void searchEnWord(String word){
     
            for (Map.Entry<String, String> pair : dictMap.entrySet()) {
                if(pair.getKey().equals(word)){
                    System.out.println(word + " - " + pair.getValue());
                    return;
                }
            }
     
     
     
     
            public void putWords () throws IOException {    //mistakes are here
     
           	 String str;
           	    String path = "D://Dictionary.txt";
     
           	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
           	    PrintWriter pw = new PrintWriter(new FileWriter(path, true));
     
           	    try {
           	       while(true){
           	            System.out.println("Enter the text : ");
           	            str = br.readLine();
           	            if(str.equalsIgnoreCase("exit"))
           	                break;
           	            else
           	                pw.println(str); }} 
           	    catch (Exception e) {
           	        }
           	    finally
           	    {
           	        pw.close();   }
           	}
     
     
            System.out.println("\tСлово '"+ word +"' не знайдено в словнику");
     
          }
         }
    Last edited by annamikilla; May 28th, 2021 at 11:39 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to fix my code?

    Please copy the full text of the error message and paste it here so we can see the exact text of the message and what statement it occurred on.
    Add a call to the printStackTrace method inside of all catch blocks.


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    annamikilla (May 28th, 2021)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to fix my code?

    Multiple markers at this line
    Where is that line?
    The error messages do not show what lines they are referring to.

    - Syntax error on token "putWords", AnnotationName expected after this token
    That looks like there is a missing } for the end of the previous method.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  2. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  3. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  4. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM

Tags for this Thread