简体   繁体   English

无法从文本字段Java获取文本

[英]Couldn't get text from the textfield Java

I have encounter a problem with my if else statement. 我的if else语句遇到问题。 I can't execute my if else statement. 我无法执行if else语句。 Actually the program should get the text from the text field and then convert to integer and validate whether the item id is found or not. 实际上,程序应该从文本字段中获取文本,然后转换为整数并验证是否找到了项目ID。

below is my partial coding: 下面是我的部分编码:

Integer itmID = new Integer(inputItemID.getText());
  Integer brwID = new Integer(inputBorrowerID.getText());
  Item itm = parent.getItems().get(itmID);
  Borrower brw = parent.getBorrowers().get(brwID);
  if (itm == null) {
      JOptionPane.showMessageDialog(this, "Item ID not found","Error", JOptionPane.ERROR_MESSAGE);
    return;
  }

You are retrieving item like Item itm = parent.getItems().get(itmID); 您正在检索类似Item itm = parent.getItems().get(itmID); , i assume that getItems() is some kind of collection . 我假设getItems()是某种collection。 You are getting itm = null because your getItems() doesn't contain any item with given itemId. 您正在获取itm = null因为您的getItems()不包含具有给定itemId的任何项目。

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

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