我对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("ntTurn 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("ntCannot able to start inquiry");
else
frm.append("ntStarted inquiry");
}
catch(Exception ex)
{
ex.printStackTrace();
frm.append("ntInquiry 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("ntDevice address : "+address+" , name : "+name);
address=name=null;
}
catch(Exception ex)
{
frm.append("ntException 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("ntInquiry 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("ntTesting 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-Polishimportbtapi.jar"在构建路径通过右键单击项目,然后选择属性->java构建路径,然后选择选项卡库,然后添加btapi.jar。
然后在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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEclasses
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:6: package javax.bluetooth does not exist
[javac] import javax.bluetooth.DeviceClass;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:7: package javax.bluetooth does not exist
[javac] import javax.bluetooth.DiscoveryAgent;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:8: package javax.bluetooth does not exist
[javac] import javax.bluetooth.DiscoveryListener;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:9: package javax.bluetooth does not exist
[javac] import javax.bluetooth.LocalDevice;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:10: package javax.bluetooth does not exist
[javac] import javax.bluetooth.RemoteDevice;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:11: package javax.bluetooth does not exist
[javac] import javax.bluetooth.ServiceRecord;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:18: cannot find symbol
[javac] symbol: class DiscoveryListener
[javac] public class BluetoothHandler implements DiscoveryListener {
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:21: cannot find symbol
[javac] symbol : class LocalDevice
[javac] location: class BluetoothHandler
[javac] LocalDevice localDevice=null;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:22: cannot find symbol
[javac] symbol : class DiscoveryAgent
[javac] location: class BluetoothHandler
[javac] DiscoveryAgent agent=null;
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.java:40: cannot find symbol
[javac] symbol : variable LocalDevice
[javac] location: class BluetoothHandler
[javac] localDevice=LocalDevice.getLocalDevice();
[javac] ^
[javac] Internal J2ME Polish class: C:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildrealGenericDefaultColorPhonede_DEsourceBluetoothHandler.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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1buildreal".
[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:Userssivakumar.j1J2ME-Polishimportmmapi.jar;C:Userssivakumar.j1J2ME-Polishimportmidp-2.0.jar;C:Userssivakumar.j1J2ME-Polishimportcldc-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:Userssivakumar.j1j2me_polish_workspacetest_bluetooth1build.xml:107: Unable to compile source code for device [Generic/DefaultColorPhone]: Compile failed; see the compiler error output for details.
我无法解决这些问题。请帮我解决这个问题。
* *谢谢,问候,
从j2me polish-eclipse的设备选择过程中选择合适的设备。如果设备在j2me中没有蓝牙设置。以上错误可能会出现,所以请选择合适的设备,而不是"虚拟默认彩色手机"。