Java me stream.close(); 日志集(“图像传输完成\n--------------\n\n等待结果…”); }捕获(IOE异常){ 日志(e); } } } } }; echo.start(); } 私有void startReadThread(最终输入流输入){ 线程读取器=新线程(){ 公开募捐{ 字节[]s=新字节[512]; //布尔标志=真; 试一试{ while(true){ int r=英寸读数; 如果(r!=-1){ 日志集(新字符串(s,0,r)); }否则{ 打破 } 睡眠(200); } }捕获(可丢弃的e){ 日志(e); }最后{ if(in!=null){ 试一试{ in.close(); }捕获(IOE异常){ } } } } }; reader.start(); } 私有void makeInformationAreaGUI(){ deleteAll(); Display.getDisplay(mymidlet).setCurrent(infoArea); } 私有void makeDeviceSelectionGUI(){ 最终列表设备=新列表(“选择设备”,List.IMPLICIT); 对于(int i=0;i

Java me stream.close(); 日志集(“图像传输完成\n--------------\n\n等待结果…”); }捕获(IOE异常){ 日志(e); } } } } }; echo.start(); } 私有void startReadThread(最终输入流输入){ 线程读取器=新线程(){ 公开募捐{ 字节[]s=新字节[512]; //布尔标志=真; 试一试{ while(true){ int r=英寸读数; 如果(r!=-1){ 日志集(新字符串(s,0,r)); }否则{ 打破 } 睡眠(200); } }捕获(可丢弃的e){ 日志(e); }最后{ if(in!=null){ 试一试{ in.close(); }捕获(IOE异常){ } } } } }; reader.start(); } 私有void makeInformationAreaGUI(){ deleteAll(); Display.getDisplay(mymidlet).setCurrent(infoArea); } 私有void makeDeviceSelectionGUI(){ 最终列表设备=新列表(“选择设备”,List.IMPLICIT); 对于(int i=0;i,java-me,Java Me,错误是 C:\Documents and Settings\admin\My Documents\NetBeansProjects\DeviceClient-MM\src\DeviceClient-MM.java:51:找不到符号 符号:等级CameraMIDlet 位置:class DeviceClientCommand 私家摄影师mymidlet C:\Documents and Settings\admin\My Documents\NetBeansProjects\DeviceClien

错误是

C:\Documents and Settings\admin\My Documents\NetBeansProjects\DeviceClient-MM\src\DeviceClient-MM.java:51:找不到符号

符号:等级CameraMIDlet

位置:class DeviceClientCommand 私家摄影师mymidlet

C:\Documents and Settings\admin\My Documents\NetBeansProjects\DeviceClient-MM\src\DeviceClient-MM.java:54:找不到符号

符号:等级CameraMIDlet

位置:class DeviceClientCommand
public DeviceClientCOMM(cameramidle m,byte[]imag)

您没有导入
cameramidle
,因此编译器不知道您指的是哪个类

假设您有一个合适的类路径条目,您应该能够添加正确的导入,这样就可以了


您确定存在供您使用的
CameraMIDlet
?我可以在JSR-135中看到一些示例代码,但我不确定它是否是要使用的完整API…

谢谢您的回复。您能帮我理解基于蓝牙的手机流媒体吗?@user243680:恐怕不行-我对此一无所知。
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;

import javax.bluetooth.BluetoothStateException;
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.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
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.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class DeviceClientCOMM implements DiscoveryListener, CommandListener {

    static final boolean DEBUG = false;
    static final String DEBUG_address = "0013FDC157C8"; // N6630

    protected UUID uuid = new UUID(0x1101); // serial port profile

    protected int inquiryMode = DiscoveryAgent.GIAC; // no pairing is needed

    protected int connectionOptions = ServiceRecord.NOAUTHENTICATE_NOENCRYPT;

    protected int stopToken = 255;

    private Command backCommand = new Command("Back", Command.BACK, 1);
    protected Form infoArea = new Form("Bluetooth Client");
    protected Vector deviceList = new Vector();
  private CameraMIDlet mymidlet;
    private byte[] imag;

    public DeviceClientCOMM(CameraMIDlet m, byte[] imag) {
        mymidlet = m;
        this.imag = imag;
        infoArea.setCommandListener(this);
        infoArea.addCommand(backCommand);
        try {
            startApp();
        } catch (MIDletStateChangeException ex) {
            ex.printStackTrace();
        }
    }

    protected void startApp() throws MIDletStateChangeException {

        makeInformationAreaGUI();

        if (DEBUG) // skip inquiry in debug mode
        {
            startServiceSearch(new RemoteDevice(DEBUG_address) {
            });
        } else {
            try {
                startDeviceInquiry();
            } catch (Throwable t) {
                log(t);
            }
        }
    }

    private void startDeviceInquiry() {
        try {
            log("Start inquiry method - this will take few seconds...");
            DiscoveryAgent agent = getAgent();
            agent.startInquiry(inquiryMode, this);

        } catch (Exception e) {
            log(e);
        }
    }

    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
        log("A device discovered (" + getDeviceStr(btDevice) + ")");
        deviceList.addElement(btDevice);
    }

    public void inquiryCompleted(int discType) {
        log("Inquiry compeleted. Please select device from combo box.");
        makeDeviceSelectionGUI();
    }

    private void startServiceSearch(RemoteDevice device) {
        try {
            log("Start search for Serial Port Profile service from " + getDeviceStr(device));
            UUID uuids[] = new UUID[]{uuid};
            getAgent().searchServices(null, uuids, device, this);
        } catch (Exception e) {
            log(e);
        }
    }

    public void servicesDiscovered(int transId, ServiceRecord[] records) {
        log("Service discovered.");
        for (int i = 0; i < records.length; i++) {
            ServiceRecord rec = records[i];
            String url = rec.getConnectionURL(connectionOptions, false);
            handleConnection(url);
        }
    }

    public void serviceSearchCompleted(int transID, int respCode) {
        String msg = null;
        switch (respCode) {
            case SERVICE_SEARCH_COMPLETED:
                msg = "the service search completed normally";
                break;
            case SERVICE_SEARCH_TERMINATED:
                msg = "the service search request was cancelled by a call to DiscoveryAgent.cancelServiceSearch()";
                break;
            case SERVICE_SEARCH_ERROR:
                msg = "an error occurred while processing the request";
                break;
            case SERVICE_SEARCH_NO_RECORDS:
                msg = "no records were found during the service search";
                break;
            case SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
                msg = "the device specified in the search request could not be reached or the local device could not establish a connection to the remote device";
                break;
        }
        log("Service search completed - " + msg);
    }

    private void handleConnection(final String url) {
        Thread echo = new Thread() {

            public void run() {
                StreamConnection stream = null;
                InputStream in = null;
                OutputStream out = null;

                try {
                    log("Connecting to server by url: " + url);
                    stream = (StreamConnection) Connector.open(url);

                    log("Bluetooth stream open.");
                    //   InputStream in = stream.openInputStream();
                    out = stream.openOutputStream();
                    in = stream.openInputStream();
                    startReadThread(in);
                    // String stringImage = Base64.encode(imag);
                    log("Start echo loop.");
                    out.write(imag);
                    out.flush();
                //       out.flush();

                //   stream.close();

                } catch (IOException e) {
                    log(e);
                } finally {
                    log("Bluetooth stream closed.");
                    if (out != null) {
                        try {

                            out.close();
                            stream.close();

                            logSet("Image Transfer done\n----------------\n\nWaiting for results...");
                        } catch (IOException e) {
                            log(e);
                        }
                    }
                }
            }
        };
        echo.start();
    }

    private void startReadThread(final InputStream in) {

        Thread reader = new Thread() {

            public void run() {

                byte[] s = new byte[512];
                //boolean flag = true;
                try {
                    while (true) {
                        int r = in.read(s);

                        if (r != -1) {

                            logSet(new String(s, 0, r));
                        }  else {
                            break;
                        }


                        Thread.sleep(200);
                    }
                } catch (Throwable e) {
                    log(e);

                } finally {
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException e) {
                        }
                    }
                }
            }
        };
        reader.start();
    }

    private void makeInformationAreaGUI() {
        infoArea.deleteAll();
        Display.getDisplay(mymidlet).setCurrent(infoArea);
    }

    private void makeDeviceSelectionGUI() {
        final List devices = new List("Select a device", List.IMPLICIT);
        for (int i = 0; i < deviceList.size(); i++) {
            devices.append(
                    getDeviceStr((RemoteDevice) deviceList.elementAt(i)), null);
        }
        devices.setCommandListener(new

              CommandListener(   ) {

    public  void commandAction(Command arg0,
        Displayable arg1)
        {
                makeInformationAreaGUI();
                startServiceSearch((RemoteDevice) deviceList.elementAt(devices.getSelectedIndex()));
            }
        });
        Display.getDisplay(mymidlet).setCurrent(devices);
    }

    synchronized private void log(String msg) {
        infoArea.append(msg);
        infoArea.append("\n\n");
    }

    synchronized private void logSet(String msg) {
        infoArea.deleteAll();
        infoArea.append(msg);
        infoArea.append("\n\n");

    }

    private void log(Throwable e) {
        log(e.getMessage());
    }

    private DiscoveryAgent getAgent() {
        try {
            return LocalDevice.getLocalDevice().getDiscoveryAgent();
        } catch (BluetoothStateException e) {
            throw new Error(e.getMessage());
        }
    }

    private String getDeviceStr(RemoteDevice btDevice) {
        return getFriendlyName(btDevice) + " - 0x" + btDevice.getBluetoothAddress();
    }

    private String getFriendlyName(RemoteDevice btDevice) {
        try {
            return btDevice.getFriendlyName(false);
        } catch (IOException e) {
            return "no name available";
        }
    }

    public void commandAction(Command arg0, Displayable arg1) {
        mymidlet.DisplayMainList();
    }
}