exception - 发送消息到移动API j2me

标签 exception compiler-errors java-me illegalargumentexception

大家好,我收到此错误:

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);    

有人有主意吗?

最佳答案

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

尝试这个:

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();
}

关于exception - 发送消息到移动API j2me,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30042092/

相关文章:

netbeans - 适用于 Linux 的诺基亚 s60 模拟器

sockets - 在 Java ME 中使用套接字连接下载二进制文件

java - 如何在 J2ME 中从大图像文件制作拇指?

c++ - 异常的复杂性

java - 在 AsyncTask 中捕获未处理异常的设计模式

android - BadParcelableException:解码时出现 ClassNotFoundException

c++ - 使用自定义删除器为 unique_ptr 返回 nullptr 失败

perl - perl eval "...propagated"记录在哪里

c# - 为什么在c#.NET中 "Enum"编译成功, "enum"编译失败?

c - 在 Solaris 上构建 Node.JS : "Use of <stdbool.h> is valid only in a c99 compilation environment."