Results 1 to 7 of 7

Thread: auto-send sms

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    auto-send sms

    hi, whats wrong with my code?


    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;

    private void sendSMS(){
    MessageConnection conn = null;
    try {
    conn = (MessageConnection) Connector.open("+1234567890");
    TextMessage msg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
    msg.setPayloadText("hello world ");
    conn.send(msg);
    } catch (IOException ex) {
    ex.printStackTrace();
    } finally{
    if(conn != null){
    try {
    conn.close();
    } catch (IOException ex) {
    ex.printStackTrace();
    }
    }
    }
    }
    when i compile this it shows

    Project "sms" loaded
    Project settings saved
    Building "sms"
    C:\WTK25\apps\sms\src\sms.java:1: 'class' or 'interface' expected
    private void sendSMS(){
    ^
    1 error
    com.sun.kvem.ktools.ExecutionException
    Build failed

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: auto-send sms

    Exactly what it says. You cannot have free functions in Java; they must be inside classes.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: auto-send sms

    Quote Originally Posted by CornedBee
    Exactly what it says. You cannot have free functions in Java; they must be inside classes.
    That's correct, and since it's a MIDlet it should look like:
    Code:
    public class MyMid extends MIDlet{
      private void sendSMS(){
        //Your Code here
      }
    }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Re: auto-send sms

    is this correct?

    Code:
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    
    public class sms extends MIDlet{
    
      private void sendSMS(){
    
            MessageConnection conn = null;
            try {
                conn = (MessageConnection) Connector.open("+639155618198");
                TextMessage msg = (TextMessage) 
    
    conn.newMessage(MessageConnection.TEXT_MESSAGE);
                msg.setPayloadText("hello world :)");
                conn.send(msg);
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally{
                if(conn != null){
                    try {
                        conn.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    }

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: auto-send sms

    basically yes, But you still have to implement startApp() , pauseApp() & destroyApp(boolean unconditional). so you don't get compile errors
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Re: auto-send sms

    thanks.. but whats that startApp() , pauseApp() & destroyApp(boolean unconditional) ?

    any samples?

  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: auto-send sms

    Those are the abstract methods from the javax.microedition.midlet.MIDlet class
    you have to implements them inorder to create instances of your class
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width