【问题标题】:Is there any difference in JComboBox.getSelectedItem().toString() and JTextField.getText()?JComboBox.getSelectedItem().toString() 和 JTextField.getText() 有什么区别吗?
【发布时间】:2021-06-03 07:25:05
【问题描述】:

我想向存储在JComboBox 中的号码发送短信,但无法正常工作,导致系统冻结。但是从JTextField 获取电话号码是有效的,但从组合框中获取它不是 并抛出此错误:

15:12:54.672 [AWT-EventQueue-0] ERROR smslib - GTW: : CMS Error 500: 
Quit retrying, message lost...

Sms Sender App

AbstractTester at = new AbstractTester() {
    @Override
    protected void test() throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); 
    }
};

OutboundNotification outboundNotification = at.new OutboundNotification();
SerialModemGateway gateway = new SerialModemGateway("", cmbPorts.getSelectedItem().toString(), 9600, "", "");
gateway.setInbound(true);
gateway.setOutbound(true);
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();

for (int i = 0; i < cmbNumbers.getItemCount(); i++) {

    OutboundMessage msg = new OutboundMessage(cmbNumbers.getItemAt(i), smsArea.getText());
    Service.getInstance().sendMessage(msg);

    txtAreaLog.append(msg.toString());
    Service.getInstance().stopService();
    Service.getInstance().removeGateway(gateway);

    JOptionPane.showMessageDialog(null, "Your Message has been sent successfully to:" + cmbNumbers.getItemAt(i) + "");
}

【问题讨论】:

  • 您真的应该尝试通过修复格式并提供更好的问题描述来改善您的问题,如果可能的话,甚至是minimal reproducible example
  • 除此之外,看看您的屏幕截图,JComboBox 中的“数字”似乎以“O”而不是“0”开头。这可能是问题所在。
  • 为什么不把字符串打印到控制台看看呢?
  • maloomeister,哈哈哈,非常感谢,iv bn 花了一周时间。从来没有想过! O vs 0 哈哈。
  • Gilbert Le Blanc ,我做到了,但没有看到 O 和 0 之间的区别。

标签: java arrays spring performance swing


【解决方案1】:

从以下位置更改您的 for 循环:

for (int i = 0; i

如下所述:

for (int i = 0; i

您的 for 循环声明中似乎存在一些问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 2018-07-28
    • 1970-01-01
    • 2013-03-14
    • 2021-07-18
    相关资源
    最近更新 更多