【问题标题】:send message to mobile api j2me发送消息到移动 api j2me
【发布时间】:2015-05-05 00:03:39
【问题描述】:

大家好,我收到了这个错误:

Uncaught exception: java.lang.IllegalArgumentException: Port Number formatted badly 
  - com.sun.midp.io.j2me.sms.Protocol.openPrimInternal(), bci=209
  - com.sun.midp.io.j2me.sms.Protocol.openPrim(), bci=4
  - javax.microedition.io.Connector.open(), bci=47
  - javax.microedition.io.Connector.open(), bci=3
  - javax.microedition.io.Connector.open(), bci=2
  - travel.entities.SendMessage$1.run(SendMessage.java:31)
  - java.lang.Thread.run(), bci=5

当转换这两个文本字段以发送它们时

public TextField tfDestination = new TextField("Destination","", 20, TextField.PHONENUMBER);
public TextField tfPort = new TextField("Port", "50001", 6, TextField.NUMERIC);

使用这种方法:

public static void execute(final String destination, final String port, final String message) {

  Thread th = new Thread(new Runnable() {

    public void run() {
      MessageConnection msgConnection;
      try {
        msgConnection = (MessageConnection) Connector.open("sms://:"+port+":"+destination);
        TextMessage textMessage = (TextMessage)msgConnection.newMessage(MessageConnection.TEXT_MESSAGE);
        textMessage.setPayloadText(message);
        msgConnection.send(textMessage);
        msgConnection.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  });

  th.start();
}

我在这一行收到错误:

msgConnection = (MessageConnection)Connector.open("sms://:"+destination+":"+port);    

有人有想法吗?

【问题讨论】:

  • 请任何人回答这个问题

标签: exception compiler-errors java-me illegalargumentexception


【解决方案1】:

您的目的地应该在端口号之前。

试试这个:

public static void execute(final String destination, final String port, final String message) {

  Thread th = new Thread(new Runnable() {

    public void run() {
      MessageConnection msgConnection;
      String address = "sms://:"+destination+":"+port;
      try {
        msgConnection = (MessageConnection) Connector.open(address);
        TextMessage textMessage = (TextMessage) msgConnection.newMessage(MessageConnection.TEXT_MESSAGE);
        textMessage.setAddress(address);
        textMessage.setPayloadText(message);
        msgConnection.send(textMessage);
        msgConnection.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  });
  th.start();
}

【讨论】:

  • 同样的错误:(未捕获的异常:java.lang.IllegalArgumentException:端口号格式错误
  • 然后尝试硬编码目的地和端口。我在我自己的一个 MIDlet 中有确切的 code-sn-p,它对我来说工作得很好。我猜那输入肯定有问题。
  • 我的朋友我怎么不懂我只是个初学者
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-03
  • 2013-06-27
  • 1970-01-01
  • 1970-01-01
  • 2013-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多