MMS through my Midlet

What jars do I need to place in my build path.I am getting an NoClassDefFound error, If some one could point me to the correct jars it would be great.

I would like to send a mms through my midlet. At the moment I am trying to get it to work with a simple hello world midlet. The send sms works but I do not know where I am going wrong with the mms, can some one please help.

* Any help appreciated*

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

publicclass TestMIDsMIDletextends MIDletimplements CommandListener{

TextBox t;

private Command exitCommand;

// The exit command

private Command sendSMS, sendMMS;

// The X command

private Display display;

// The display for this MIDlet

public TestMIDsMIDlet(){

display = Display.getDisplay(this);

exitCommand =new Command("Exit", Command.SCREEN, 2);

sendSMS =new Command("SMS", Command.SCREEN, 1);

sendMMS =new Command("MMS", Command.SCREEN, 1);

}

publicvoid startApp(){

t =new TextBox("Hello MIDlet", null, 56, 0);

t.addCommand(exitCommand);

t.addCommand(sendSMS);

t.addCommand(sendMMS);

t.setCommandListener(this);

display.setCurrent(t);

}

publicvoid pauseApp(){}

publicvoid destroyApp(boolean unconditional){}

publicvoid commandAction(Command c, Displayable s){

if (c == exitCommand){

destroyApp(false);

notifyDestroyed();

}

if (c == sendSMS){

SendMessage sms =new SendMessage(t);

sms.sendSms();

}

if(c == sendMMS){

try{

SendMessage sms =new SendMessage(t);

sms.sendMms();

}catch(Exception e){

System.out.println("Problem");

}

}

}

}

import java.io.IOException;

import java.util.Vector;

import javax.microedition.io.Connector;

import javax.microedition.lcdui.TextBox;

import javax.microedition.midlet.*;

import javax.wireless.messaging.*;

publicclass SendMessageextends MIDlet{

TextBox t;

private Vector parts =new Vector();

public SendMessage(TextBox t){

this.t = t;

}

publicvoid sendSms(){

try{

try{

String addr ="sms://"+t.getString();

System.out.println("addr = " +addr);

MessageConnection conn = (MessageConnection)Connector.open(addr);

TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);

msg.setPayloadText("Hello World!");

conn.send(msg);

}catch (Exception e){

/// mhhhhh t.setString(e.toString());

//printStackTrace();

}

}catch(Exception ee){

t.setString(ee.toString());

}

}

publicvoid sendMms(){

String appID = getAppProperty("MMS-ApplicationID");

String addr ="mms://" + t.getString() + appID;

MessageConnection mmsconn =null;

try{

/** Open the message connection. */

mmsconn = (MessageConnection) Connector.open(addr);

MultipartMessage mmmessage =(MultipartMessage) mmsconn.newMessage(

MessageConnection.MULTIPART_MESSAGE);

mmmessage.setAddress(addr);

MessagePart[] parts = getParts();

for (int i = 0; i < parts.length; i++)

{

mmmessage.addMessagePart(parts[i]);

}

mmmessage.setSubject("MMS Text");

mmsconn.send(mmmessage);

}

catch (Exception e){

}

if (mmsconn !=null){

try{

mmsconn.close();

}

catch (IOException ioe){}

}

}

protectedvoid destroyApp(boolean arg0)throws MIDletStateChangeException{

// TODO Auto-generated method stub

}

protectedvoid pauseApp(){

// TODO Auto-generated method stub

}

protectedvoid startApp()throws MIDletStateChangeException{

// TODO Auto-generated method stub

}

public MessagePart[] getParts(){

// parts is a Vector that contains Mulitpart messages

MessagePart[] partsArray =new MessagePart[parts.size()];

parts.copyInto(partsArray);

return partsArray;

}

}

Message was edited by:

-fluffy-

null

[8804 byte] By [-fluffy-a] at [2007-11-27 10:32:24]
# 1

Here goes your code with bit modification :

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

public class TestMIDsMIDlet extends MIDlet implements CommandListener {

TextBox t;

private Command exitCommand;

// The exit command

private Command sendSMS, sendMMS;

// The X command

private Display display;

// The display for this MIDlet

public TestMIDsMIDlet () {

display = Display.getDisplay (this);

exitCommand = new Command ("Exit", Command.SCREEN, 2);

sendSMS = new Command ("SMS", Command.SCREEN, 1);

sendMMS = new Command ("MMS", Command.SCREEN, 1);

}

public void startApp () {

t = new TextBox ("Hello MIDlet", null, 56, 0);

t.addCommand (exitCommand);

t.addCommand (sendSMS);

t.addCommand (sendMMS);

t.setCommandListener (this);

display.setCurrent (t);

}

public void pauseApp () { }

public void destroyApp (boolean unconditional) { }

public void commandAction (Command c, Displayable s) {

if (c == exitCommand) {

destroyApp (false);

notifyDestroyed ();

}

if (c == sendSMS) {

final SendMessage sms = new SendMessage (this, t);

try {

sms.startApp ();

} catch (MIDletStateChangeException ex) {

ex.printStackTrace ();

}

new Thread (new Runnable () {

public void run () {

sms.sendSms ();

}

}).start ();

}

if(c == sendMMS){

final SendMessage sms = new SendMessage (this, t);

try {

sms.startApp ();

} catch (MIDletStateChangeException ex) {

ex.printStackTrace ();

}

new Thread (new Runnable () {

public void run () {

sms.sendMms ();

}

}).start ();

}

}

}

import java.io.IOException;

import java.util.Vector;

import javax.microedition.io.Connector;

import javax.microedition.lcdui.TextBox;

import javax.microedition.midlet.*;

import javax.wireless.messaging.*;

public class SendMessage {

MIDlet midlet;

TextBox t;

private Vector parts = new Vector ();

public SendMessage (MIDlet midlet, TextBox t){

this.midlet = midlet;

this.t = t;

}

public void sendSms (){

try{

try {

String addr = "sms://"+t.getString ();

System.out.println ("addr = " +addr);

MessageConnection conn = (MessageConnection)Connector.open (addr);

TextMessage msg = (TextMessage)conn.newMessage (MessageConnection.TEXT_MESSAGE);

msg.setPayloadText ("Hello World!");

conn.send (msg);

} catch (Exception e) {

/// mhhhhh t.setString(e.toString());

//printStackTrace();

}

} catch(Exception ee){

t.setString (ee.toString ());

}

}

public void sendMms (){

String appID = midlet.getAppProperty ("MMS-ApplicationID");

String addr = "mms://" + t.getString () + appID;

MessageConnection mmsconn = null;

try{

/** Open the message connection. */

mmsconn = (MessageConnection) Connector.open (addr);

MultipartMessage mmmessage =(MultipartMessage) mmsconn.newMessage (

MessageConnection.MULTIPART_MESSAGE);

mmmessage.setAddress (addr);

MessagePart[] parts = getParts ();

for (int i = 0; i < parts.length; i++) {

mmmessage.addMessagePart (parts[i]);

}

mmmessage.setSubject ("MMS Text");

mmsconn.send (mmmessage);

} catch (Exception e) {

}

if (mmsconn != null) {

try {

mmsconn.close ();

} catch (IOException ioe) {}

}

}

protected void destroyApp (boolean arg0) throws MIDletStateChangeException {

// TODO Auto-generated method stub

}

protected void pauseApp () {

// TODO Auto-generated method stub

}

protected void startApp () throws MIDletStateChangeException {

// TODO Auto-generated method stub

}

public MessagePart[] getParts () {

// parts is a Vector that contains Mulitpart messages

MessagePart[] partsArray = new MessagePart[parts.size ()];

parts.copyInto (partsArray);

return partsArray;

}

}

And don't forget to add WMA 2.0 (Wireless Messaging API 2.0) while building the project.

find_suvro@SDNa at 2007-7-28 18:16:31 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Thanks for that, I am not sure whats wrong now but its giving me a stack trace like the following

Running with storage root SonyEricsson_K750_Emu

Method............: 170f420 'TestMIDsMIDlet.commandAction (virtual)'

Stack Chunk.......: 13113a4

Frame Pointer.....: 13114d0

Current IP........: 170f2df = 170f290 + offset 79

Previous Frame....: 13114a4

Previous IP.......: 101de76e (offset 282)

Frame size........: 5 (3 arguments, 2 local variables)

Argument[0].......: 170e800

Argument[1].......: 170e714

Argument[2].......: 170e65c

Local[3]..........: 13114b8

Local[4]..........: 10187b2c

Method............: 101582f8 'javax/microedition/lcdui/Display$DisplayAccessor.commandAction (virtual)'

Stack Chunk.......: 13113a4

Frame Pointer.....: 13114a4

Current IP........: 101de76e = 101de654 + offset 282

etc etc, and also an alert:"ALERT: Creating primitive array?2

-fluffy-a at 2007-7-28 18:16:31 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Can't say about this. Try on the device itself. May be it work.

find_suvro@SDNa at 2007-7-28 18:16:31 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

It did thank you, Well sort of... it was not sending the actual mms, the sms was fine, I surrounded the mms.send with a try and it couldn't send it. Any ideas with that?

-fluffy-a at 2007-7-28 18:16:31 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

Well, I figured out why it wouldnt send, basically I was using appID when I shouldnt have been using it as I only wanted to send to another phones inbox not another midlet, incase anyone reads this thread. Thanks for your help

-fluffy-a at 2007-7-28 18:16:31 > top of Java-index,Java Mobility Forums,Java ME Technologies...