我找不到符号方法打开(java.lang.String)错误消息。我知道我出错了。整个程序运行正常。我只有这一个错误。它用于一个项目,需要在2天内提交。我希望你能快点回答我。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
public class DeviceON extends MIDlet implements CommandListener {
private Command exitCommand; // The exit command
private Display display; // The display for this MIDlet
public String btConnectionURL ;
public OutputStream out ;
private Form mainForm;
private Alert conf ;
private Command tryagainCommand ;
public StreamConnection Connector;
public interface StreamConnection{}
public DeviceON() {
display = Display.getDisplay(this);
conf = new Alert("Sucessfull","Device is ON.\n\nDevice Control",null,AlertType.CONFIRMATION);
exitCommand = new Command("Exit", Command.EXIT, 0);
tryagainCommand = new Command("Try Again",Command.OK,1);
}
public void startApp() {
try{
mainForm = new Form ("Bluetooth Device Control");
btConnectionURL = "btspp://" + "0019A40244C5" + ":1;authenticate=true;encrypt=false;master=false";
StreamConnection connection = (StreamConnection)Connector.open(btConnectionURL);
out = connection.openOutputStream();
out.write(170);
out.write(1) ;
out.flush() ;
conf.setTimeout(4000);
display.setCurrent(conf, mainForm);
try {
Thread.sleep(4000);
} catch (Exception e) {}
destroyApp(false);
notifyDestroyed();
}
catch (IOException ioe) {
mainForm = new Form ("Bluetooth Device Control");
ioe.printStackTrace();
mainForm = new Form ("Bluetooth Device Control");
mainForm.append("Connection Failed");
mainForm.addCommand(tryagainCommand) ;
mainForm.addCommand(exitCommand);
display.setCurrent(mainForm);
mainForm.setCommandListener(this);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
else {
if (c == tryagainCommand)
startApp() ;
}
}
}
答案 0 :(得分:0)
而不是
(StreamConnection)Connector.open(btConnectionURL);
待办事项
((StreamConnection)Connector).open(btConnectionURL);
调用方法
之前的连接器