Reputation: 4323
I am creating simple midlet for Bluetooth communication with server but I can't get it to work on my phone, when I Try to run it in Eclipse/Emulator everything works fine, but on the phone I get "Cannot create MIDlet instance: java.lang.ClassNotFoundException"
I saw somewhere that this exception is mostly path related, but I don't have any external jars or multiple packages.
Here is the code:
package j2meclient;
import java.io.OutputStream;
import javax.bluetooth.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class J2MEClientMidlet extends MIDlet implements CommandListener,
Runnable {
Display d;
Command cmExit, cmConnect;
Form f;
Thread t;
String connString;
public J2MEClientMidlet() {
f = new Form("Client");
cmExit = new Command("Exit", Command.EXIT, 1);
cmConnect = new Command("Connect", Command.ITEM, 2);
f.addCommand(cmExit);
f.addCommand(cmConnect);
f.setCommandListener(this);
}
public void startApp() {
if (d == null) {
d = Display.getDisplay(this);
d.setCurrent(f);
t = new Thread(this);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == cmExit) {
destroyApp(false);
notifyDestroyed();
}
if (c == cmConnect) {
t.start();
}
}
public void run() {
try {
LocalDevice local = LocalDevice.getLocalDevice();
DiscoveryAgent agent = local.getDiscoveryAgent();
connString = agent.selectService(new UUID(
"86b4d249fb8844d6a756ec265dd1f6a3", false),
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
} catch (Exception e) {
}
if (connString != null) {
try {
StreamConnection conn = (StreamConnection) Connector
.open(connString);
OutputStream out = conn.openOutputStream();
Thread.sleep(2000);
out.write("Hello, World".getBytes());
out.close();
conn.close();
f.append("Message sent correctly");
} catch (Exception ex) {
f.append("IOException: ");
f.append(ex.getMessage());
}
} else {
f.append("Unable to locate service");
}
}
}
JAD;
MIDlet-1: J2MEClient,,J2MEClient
MIDlet-Jar-Size: 2254
MIDlet-Jar-URL: BTClient.jar
MIDlet-Name: BTClient Midlet Suite
MIDlet-Vendor: Midlet Suite Vendor
MIDlet-Version: 1.0.0
MicroEdition-Configuration: CLDC-1.1
MicroEdition-Profile: MIDP-2.0
Any ideas why I can't run this on phone?
Upvotes: 1
Views: 409
Reputation: 3226
Your class file for the midlet is named J2MEClientMidlet
but on the jad file it is defined as J2MEClient. Midlet class file name must match the definition on jad to run successfully from jad.
Upvotes: 1