Cannot resolve method setText(java.lang.String)



  • I can't figure out what the problem of my code attempt is, but in Main Class, it doesn't work. area.getText(na.l);

    public class Main {
    

    public static void main(String[] args) {
    Na na = new Na();
    JFrame kl = new JFrame();
    JTextArea area = new JTextArea();
    area.getText (na.l);
    /* тут (na.l) подчеркивается красным, а при наведении курсора пишет это предложение. */
    }
    }

    class Na {
    Main maiin = new Main();
    String l = "Rain";
    }



  • Class JTextArea Two methods. getText:

    public String getText()
    

    (sighs) https://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#getText() )

    and

    public String getText(int offs, int len) throws BadLocationException
    

    (sighs) https://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#getText(int,%20int) )

    Method getText one type of argument String This class doesn't. There's a mistake.

    I suspect you need to either

    na.l = area.getText();
    

    or

    area.setText(na.l);
    

    The latter uses the method.

    public void setText(String t)
    

    (sighs) https://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#setText(java.lang.String) )


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2