帮我解决j2me polish -bluetooth问题

时间:2011-08-12 05:20:27

标签: java java-me bluetooth j2mepolish

我有一个j2me波兰怀疑。我正在使用eclipse IDE。以下是我的j2me文件:

BluetoothHandler.java

import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.microedition.lcdui.Form;

/**
 * @author sivakumar.j1
 *
 */
public class BluetoothHandler implements DiscoveryListener {

 Form frm=null;
 LocalDevice localDevice=null;
 DiscoveryAgent agent=null;
 boolean inquiry_started=false;
 boolean bluetooth_turned_on=false;

 public BluetoothHandler(Form frm1)
 {
  frm=frm1;
  frm1=null;

 }

 public void doDeviceSearching()
 {
  localDevice=null;
  agent=null;

  try
  {
   localDevice=LocalDevice.getLocalDevice();
   localDevice.setDiscoverable(DiscoveryAgent.GIAC);
   bluetooth_turned_on=true;
  }
  catch(Exception ex)
  {
   ex.printStackTrace();
   frm.append("\n\tTurn on bluetooth in ur device");
   bluetooth_turned_on=false;
  }

  agent=localDevice.getDiscoveryAgent();
  inquiry_started=false;

  if(this.bluetooth_turned_on)
  {
   try
   {
    inquiry_started=agent.startInquiry(DiscoveryAgent.GIAC,this);
    if(inquiry_started==false)
     frm.append("\n\tCannot able to start inquiry");
    else
     frm.append("\n\tStarted inquiry");

   }
   catch(Exception ex)
   {
    ex.printStackTrace();
    frm.append("\n\tInquiry starting exception : "+ex.toString());
   }
  }

 }
 /* (non-Javadoc)
  * @see javax.bluetooth.DiscoveryListener#deviceDiscovered(javax.bluetooth.RemoteDevice, javax.bluetooth.DeviceClass)
  */
 public void deviceDiscovered(RemoteDevice remoteDevice1, DeviceClass arg1) {
  // TODO Auto-generated method stub
  RemoteDevice remoteDevice=remoteDevice1;
  String address=null;
  String name=null;
  try
  {
   address=remoteDevice.getBluetoothAddress();
   name=remoteDevice.getFriendlyName(true);
   frm.append("\n\tDevice address : "+address+" , name : "+name);
   address=name=null;
  }
  catch(Exception ex)
  {
   frm.append("\n\tException in getting name & address of device : "+ex.toString());
  }

 }

 /* (non-Javadoc)
  * @see javax.bluetooth.DiscoveryListener#inquiryCompleted(int)
  */
 public void inquiryCompleted(int arg0) {
  // TODO Auto-generated method stub
  frm.append("\n\tInquiry completed");
 }

 /* (non-Javadoc)
  * @see javax.bluetooth.DiscoveryListener#serviceSearchCompleted(int, int)
  */
 public void serviceSearchCompleted(int arg0, int arg1) {
  // TODO Auto-generated method stub

 }

 /* (non-Javadoc)
  * @see javax.bluetooth.DiscoveryListener#servicesDiscovered(int, javax.bluetooth.ServiceRecord[])
  */
 public void servicesDiscovered(int arg0, ServiceRecord[] arg1) {
  // TODO Auto-generated method stub

 }

}

BluetoothMidlet.java

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class BluetoothMidlet extends MIDlet implements CommandListener
{

 Form frm=null;
 Display display=null;
 Command cmdExit=null;
 Command cmdPair=null;
 BluetoothHandler handler=null;

 public BluetoothMidlet() {
  // TODO Auto-generated constructor stub

  display=Display.getDisplay(this);
  frm=new Form("Tesing bluetooth");
  cmdExit=new Command("Exit",Command.EXIT,0);
  cmdPair=new Command("Pair",Command.OK,1);
  frm.append("\n\tTesting bluetooth");
  frm.addCommand(this.cmdExit);
  frm.addCommand(this.cmdPair);
  frm.setCommandListener(this);

  display.setCurrent(frm);
 }

 protected void destroyApp(boolean flag) throws MIDletStateChangeException {
  // TODO Auto-generated method stub



  this.cmdExit=this.cmdPair=null;
  this.frm=null;
  this.display=null;

  this.notifyDestroyed();
 }

 protected void pauseApp() {
  // TODO Auto-generated method stub

 }

 protected void startApp() throws MIDletStateChangeException {
  // TODO Auto-generated method stub

 }

 public void commandAction(Command cmd, Displayable arg1) {
  // TODO Auto-generated method stub

  if(cmd==this.cmdExit)
  {
   try
   {
    this.destroyApp(true);
   }
   catch(Exception ex)
   {
    ex.printStackTrace();
    this.notifyDestroyed();
   }
  }
  else if(cmd==this.cmdPair)
  {
   handler=null;
   this.handler=new BluetoothHandler(frm);
   handler.doDeviceSearching();
  }

 }

}

以上是我的蓝牙应用程序j2me中的两个java文件。当我在移动设备中部署并执行它时工作正常。(显示发现的设备地址和名称)。

但我创建了一个新的j2me打磨项目。将两个java文件复制到j2me polish项目的源目录中。我还在构建路径中添加“\ J2ME-Polish \ import \ btapi.jar”,方法是右键单击然后选择properties-> java build path,然后选择选项卡库,然后添加btapi.jar。

然后我使用wirless toolkit simulaotr在eclipse中运行j2me polish应用程序。然后出现以下错误

错误:

j2mepolish:
[j2mepolish] info: the license attribute is no longer supported. Please place your license.key file either to ${project.home} or to ${polish.home}.
[j2mepolish] J2ME Polish 2.0 (2008-02-10) (GPL License)
[j2mepolish] Loading device database...
[j2mepolish] using locale [de_DE]...
[j2mepolish] assembling resources for device [Generic/DefaultColorPhone].
[j2mepolish] preprocessing for device [Generic/DefaultColorPhone].
[j2mepolish] Warning: CSS-Style [focused] not found, now using the default style instead. If you use Forms or Lists, you should define the style [focused].
[j2mepolish] Warning: CSS style [title] not found, you should define it for designing the titles of screens.
[j2mepolish] processing locale code...
[j2mepolish] compiling for device [Generic/DefaultColorPhone].
[j2mepolish-javac-Generic/DefaultColorPhone] Compiling 287 source files to C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\classes
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:6: package javax.bluetooth does not exist
    [javac] import javax.bluetooth.DeviceClass;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:7: package javax.bluetooth does not exist
    [javac] import javax.bluetooth.DiscoveryAgent;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:8: package javax.bluetooth does not exist
    [javac] import javax.bluetooth.DiscoveryListener;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:9: package javax.bluetooth does not exist
    [javac] import javax.bluetooth.LocalDevice;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:10: package javax.bluetooth does not exist
    [javac] import javax.bluetooth.RemoteDevice;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:11: package javax.bluetooth does not exist
    [javac] import javax.bluetooth.ServiceRecord;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:18: cannot find symbol
    [javac] symbol: class DiscoveryListener
    [javac] public class BluetoothHandler implements DiscoveryListener {
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:21: cannot find symbol
    [javac] symbol  : class LocalDevice
    [javac] location: class BluetoothHandler
    [javac] LocalDevice localDevice=null;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:22: cannot find symbol
    [javac] symbol  : class DiscoveryAgent
    [javac] location: class BluetoothHandler
    [javac] DiscoveryAgent agent=null;
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:76: cannot find symbol
    [javac] symbol  : class RemoteDevice
    [javac] location: class BluetoothHandler
    [javac] public void deviceDiscovered(RemoteDevice remoteDevice1, DeviceClass arg1) {
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:76: cannot find symbol
    [javac] symbol  : class DeviceClass
    [javac] location: class BluetoothHandler
    [javac] public void deviceDiscovered(RemoteDevice remoteDevice1, DeviceClass arg1) {
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:114: cannot find symbol
    [javac] symbol  : class ServiceRecord
    [javac] location: class BluetoothHandler
    [javac] public void servicesDiscovered(int arg0, ServiceRecord[] arg1) {
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:40: cannot find symbol
    [javac] symbol  : variable LocalDevice
    [javac] location: class BluetoothHandler
    [javac] localDevice=LocalDevice.getLocalDevice();
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:41: cannot find symbol
    [javac] symbol  : variable DiscoveryAgent
    [javac] location: class BluetoothHandler
    [javac] localDevice.setDiscoverable(DiscoveryAgent.GIAC);
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:58: cannot find symbol
    [javac] symbol  : variable DiscoveryAgent
    [javac] location: class BluetoothHandler
    [javac] inquiry_started=agent.startInquiry(DiscoveryAgent.GIAC,this);
    [javac] ^
    [javac] Internal J2ME Polish class: C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real\Generic\DefaultColorPhone\de_DE\source\BluetoothHandler.java:78: cannot find symbol
    [javac] symbol  : class RemoteDevice
    [javac] location: class BluetoothHandler
    [javac] RemoteDevice remoteDevice=remoteDevice1;
    [javac] ^
    [javac] 16 errors
    [javac] An internal class of J2ME Polish could not be compiled. Please try a clean rebuild by either calling "ant clean j2mepolish" or by removing the working directory "C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build\real".
    [javac] When an API-class was not found, you might need to define where to find the device-APIs. Following classpath has been used: [C:\Users\sivakumar.j1\J2ME-Polish\import\mmapi.jar;C:\Users\sivakumar.j1\J2ME-Polish\import\midp-2.0.jar;C:\Users\sivakumar.j1\J2ME-Polish\import\cldc-1.1.jar;C:/Users/sivakumar.j1/J2ME-Polish/import/mmapi.jar;C:/Users/sivakumar.j1/J2ME-Polish/import/wmapi.jar;C:/Users/sivakumar.j1/J2ME-Polish/import/pdaapi.jar].

BUILD FAILED
C:\Users\sivakumar.j1\j2me_polish_workspace\test_bluetooth1\build.xml:107: Unable to compile source code for device [Generic/DefaultColorPhone]: Compile failed; see the compiler error output for details.

我无法解决问题。请帮我解决问题。

**谢谢&的问候,

1 个答案:

答案 0 :(得分:0)

从j2me polish-eclipse的设备选择程序中选择合适的设备。如果设备在j2me polish中没有蓝牙设置。上面的错误可能很多,所以选择“virtul默认彩色手机”以外的相应设备