2012-12-26 36 views
1

我正在创建与服务器的蓝牙通信的简单midlet,但我无法让它在我的手机上工作,当我尝试在Eclipse/Emulator中运行它时,一切正常,但是我得到的手机“无法创建MIDlet实例:java.lang.ClassNotFoundException”Midlet在模拟器中工作,ClassNotFoundException在手机

我看到这个异常大部分路径相关,但我没有任何外部的jar或多个包。

下面是代码:

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 

任何想法,为什么我不能在手机上运行此?

+0

[Midelt在调用蓝牙API时崩溃]的可能重复(http://stackoverflow.com/questions/14044091/midelt-crashes-when-calling-bluetooth-api) – gnat

回答

1

MIDlet的类文件名为J2MEClientMidlet,但在jad文件上它被定义为J2MEClient。 Midlet类文件名必须与jad上的定义匹配才能从jad成功运行。

相关问题