[英]Taking input from JTextField and using it to search arraytable
I have a arraylist
which take a string
eg "String searchFor = "London;"
and then runs runs in the loop
and then shows data related to the string, if I try change the string to String searchFor = tfSearch.getText();
then I get <init>
error 我有一个
arraylist
,它接受一个string
例如"String searchFor = "London;"
,然后在loop
运行,然后显示与该字符串相关的数据,如果我尝试将字符串更改为String searchFor = tfSearch.getText();
然后我收到<init>
错误
I think problem is that the arraylist doesn't wait for the input to be taken from the JTextField 我认为问题是arraylist不等待从JTextField接受输入
If you read the documentation it says: 如果您阅读文档说明:
Throws:
NullPointerException - if the document is null
So, your JTextField
must be null
. 因此,您的
JTextField
必须为null
。
You need to execute getText()
on a actionListener
, for example. 例如,您需要在
actionListener
上执行getText()
。 Probably, the way you're doing it now, the JTextField
is null
yet, and you're not waiting for an input from the user. 可能是您现在的方式,
JTextField
为null
,并且您不必等待用户的输入。 That way, when the user fills that field and clicks Enter
, you can get the text from the field. 这样,当用户填写该字段并单击
Enter
,您可以从该字段中获取文本。
Check out this example 看看这个例子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.