|
-
Jul 26th, 2006, 12:48 AM
#1
Thread Starter
Fanatic Member
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
-
Jul 26th, 2006, 04:54 AM
#2
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.
-
Jul 26th, 2006, 12:07 PM
#3
Re: auto-send sms
 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
-
Jul 27th, 2006, 01:27 AM
#4
Thread Starter
Fanatic Member
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();
}
}
}
}
}
-
Jul 27th, 2006, 04:45 AM
#5
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
-
Jul 27th, 2006, 08:07 AM
#6
Thread Starter
Fanatic Member
Re: auto-send sms
thanks.. but whats that startApp() , pauseApp() & destroyApp(boolean unconditional) ?
any samples?
-
Jul 27th, 2006, 10:46 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|