简体   繁体   English

不存在的错误

[英]Errors that don't exist

Umm. 嗯。 This is awkward but I'm getting some errors that say stuff that is totally untrue. 这很尴尬,但我遇到了一些错误,这些错误说的是完全不真实的内容。

Could someone give me a suggestion on how to fix it. 有人可以给我建议如何解决它。 I'm new to java so simple answers would be the best. 我是Java新手,所以简单的答案将是最好的。

Thanks. 谢谢。

 public class Project1
    {
    public static void main( String [] args )
    {
        System.out.println();
        String output = new String();
        String inital = new String();
        inital = english_to_morse();

        for( int k = 0; k < inital.length(); k++)
        {
            output += morse(inital.charAt( k ));
        }

            System.out.print(output);
            System.out.println();
    }
        public static void choice()
    {
        int user_choice = 0; ///This is the method giving me grief!!!!!!
        user_choice = Input.getInt("Enter 1 if you want to change English to Morse code, and enter 2 to change Morse code to English");
        if(user_choice == 1)
        {
            english_to_morse();

        }
        if(user_choice == 2)
        {
            morse_to_english();
        }

    public static String english_to_morse() 
    {
      String user_input = new String();

      user_input = Input.getString("Enter a phrase and I'll convert it to Morse Code");

      return user_input.toLowerCase();
    }

    public static String morse_to_english() 
    {
      String user_input = new String();

      user_input = Input.getString("Enter a phrase in Morse Code and I'll convert it to English");

      return user_input.toLowerCase();
    }

    public static String morse(char letter)
    {
        String output = new String();
        char[] alphabet_numbers = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ' };
        String morse_code[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "|" };

        for( int j = 0; j < alphabet_numbers.length; j++ )
        {
            if (alphabet_numbers[j]==letter)
            {
                output = morse_code[j];
            }
        }
        return output + " ";
    }   
}

This is the problem: 这就是问题:

public static void choice()
{
    int user_choice = 0; ///This is the method giving me grief!!!!!!
    user_choice = Input.getInt("Enter 1 if you want to change English to Morse code, and enter 2 to change Morse code to English");
    if(user_choice == 1)
    {
        english_to_morse();

    }
    if(user_choice == 2)
    {
        morse_to_english();
    }

public static String english_to_morse() 

You never finish the choice() method - so you can't start the english_to_morse method. 您永远不会完成choice()方法,因此无法启动english_to_morse方法。

I strongly suspect that the first error message from the compiler was at the start of the english_to_morse method. 我强烈怀疑来自编译器的第一条错误消息是在english_to_morse方法的开头。 Once you're source is that broken (trying to declare one method inside another) it shouldn't be a surprise that other error messages may seem strange. 一旦您发现问题已损坏(试图在另一个方法中声明一个方法),其他错误消息似乎很奇怪也就不足为奇了。

It's a good idea to: 这是一个好主意:

  • Compile often , and fix problems as soon as they occur. 经常编译,并在问题发生后立即解决。 Then if you suddenly get a slew of errors, you know that it can only be due to what you've done very recently. 然后,如果您突然遇到许多错误,您就会知道这只能归因于您最近所做的事情。
  • A huge number of errors is usually due to something like this - look at the first error message, or at least where you start getting a lot of errors, and that can often find the problem. 大量的错误通常是由于诸如此类的原因-查看第一个错误消息,或者至少从开始出现很多错误的位置开始,通常可以发现问题。
  • Getting the IDE to format your code can help you find missing braces too. 获取IDE格式化代码的格式也可以帮助您找到缺失的花括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM