2

大家好,我得到这个错误:发送短信到移动API J2ME

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

任何人有想法?

+0

请人有一个答案此 – user3010971

回答

0

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

试试这个:

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

同样的错误:(未捕获异常:java.lang.IllegalArgumentException异常:端口号格式的严重 – user3010971

+0

尝试硬编码的目的地和端口,然后我有在我自己的一个MIDlet中使用了精确的代码片段,它对我来说工作正常。我在猜测输入的东西肯定出问题了。 –

+0

我的朋友怎么样?我不明白我只是一个初学者 – user3010971