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