我得到一个无法找到符号方法打开(java.lang.String)错误。我不知道我出错了。公共StreamConnection连接器;

时间:2015-04-11 19:41:05

标签: java android android-bluetooth

我找不到符号方法打开(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() ;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

而不是

(StreamConnection)Connector.open(btConnectionURL);

待办事项

((StreamConnection)Connector).open(btConnectionURL);

调用方法

之前的连接器