I can not understand the problem of my attempt to code, but in the Main class area.getText (na.l) does not work;

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"; } 

Closed due to the fact that off-topic participants zRrr , user194374, Streletz , enzo , Grundy Jul 3 '16 at 6:59 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - zRrr, Community Spirit, Streletz, enzo, Grundy
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    Taki get or is it set? If the first, then, surely, there is a mute version of the method with a -l argument. - JuriySPb
  • 2
    The get Text () method has no arguments. It returns the current text content of the object, if the object can contain text at all and has such a getter - pavlofff

1 answer 1

The JTextArea class has two getText methods:

 public String getText() 

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

and

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

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

This class does not have a getText with a single argument of type String . Hence the error.

I suspect that you need either

 na.l = area.getText(); 

or

 area.setText(na.l); 

The latter uses the method

 public void setText(String t) 

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