pls help me !!!!!!!!

Discussion in 'General Computer Support' started by Dharanya, Dec 26, 2011.

  1. Dharanya

    Dharanya

    Joined:
    Dec 26, 2011
    Messages:
    2
    package BTClient;
    import java.util.*;
    import javax.bluetooth.*;
    import javax.bluetooth.UUID;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.StreamConnection.*;
    import javax.bluetooth.RemoteDevice;
    import javax.bluetooth.DeviceClass;
    import javax.bluetooth.ServiceRecord;
    import javax.microedition.midlet.*;
    public class BTClient implements DiscoveryListener, Runnable {
    // DiscoveryListener public static final String uuidString = "0123456789ABCDEF0123456789ABCDEF";
    public static UUID uuid;
    private LocalDevice localDevice;
    String localBTAddress;
    String localBTName;
    DiscoveryAgent discoveryAgent;
    Thread th;
    Thread readWorkTh;
    Thread writeWorkTh;
    StreamConnection conn;
    boolean exitFlag;
    boolean BTReady;
    DataInputStream in;
    DataOutputStream out;
    String sendText = "";
    Hashtable remoteDevices = new Hashtable();
    java.util.Hashtable String url;
    ServiceRecord serviceRecord;
    public BTClient() {

    th = new Thread(this); th.start();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // @SuppressWarnings("empty-statement")
    // @SuppressWarnings("empty-statement")
    public void run(boolean exitFlag) {
    if (!initBT()) {
    return;
    }
    try {

    synchronized (this) {

    try {
    wait();//»áÊÍ·ÅÕâ¸öËø£¬ÈÃÆäËüÏß³ÌÓлú»áÔËÐС£ }
    }
    catch (InterruptedException e) { e.printStackTrace();}
    }

    if (exitFlag) return;//·µ»Ø
    search(); ///////////////////////////// ///////////////////////////// // µÈ´ýURL×¼±¸ºÃ synchronized (this) { //µÈµ½±»»½ÐѺó ÔÙ¼ÌÐøÔËÐÐ
    try {
    wait();//»áÊÍ·ÅÕâ¸öËø£¬ÈÃÆäËüÏß³ÌÓлú»áÔËÐС£
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    catch (InterruptedException e) { e.printStackTrace();
    ////

    if (exitFlag) return;//·µ»Ø
    conn = (StreamConnection) Connector.open(url);
    in = conn.openDataInputStream();
    out = conn.openDataOutputStream();
    readWorkTh = new ReadWorkThread();
    readWorkTh.start();
    writeWorkTh = new WriteWorkThread();
    writeWorkTh.start(); BTReady = true;
    } catch (IOException e) {
    return;//·µ»Ø
    } catch (SecurityException e) {
    return;//·µ»Ø
    }
    th = null;
    } ////////////////////////////////////////////////////////////////////////////////////////////////////
    public boolean initBT() { //³õʼ»¯À¶ÑÀ-ÎÄÎÄ·ç ÕâºÜ¼òµ¥ ³õʼ»¯¾Í¿ÉÒÔÁËÖ÷ÒªÊǵØÖ·£¡
    boolean success = false;
    try {
    uuid = new UUID(uuidString, false);// ÎÒÃǵÄUUID // È¡µÃ±¾µØÉ豸ʵÀý
    localDevice = LocalDevice.getLocalDevice(); // ¼Ç¼À¶ÑÀµØÖ·
    localBTAddress = localDevice.getBluetoothAddress(); // ¼Ç¼À¶ÑÀÃû³Æ
    localBTName = localDevice.getFriendlyName();
    localDevice.setDiscoverable(DiscoveryAgent.GIAC); // È¡µÃÀ¶ÑÀ´úÀí
    discoveryAgent = localDevice.getDiscoveryAgent();
    success = true;
    } catch (Exception e) {
    System.err.println("³õʼ»¯À¶ÑÀÉ豸ʧ°Ü£º" + e);
    }
    return success;
    } ////////////////////////////////////////////////////////////////////////////////////////////////////
    public void search() {// ËÑË÷É豸£¬ËÑË÷·þÎñ
    try {
    //remoteDevices¹þʲ±í
    // Çå³ýremoteDevices
    RemoteDevice remoteDevice;
    remoteDevices.clear(); //cacheDevices++preDevices==remoteDevices RemoteDevice[] cacheDevices = discoveryAgent.retrieveDevices(DiscoveryAgent.CACHED);
    // class RemoteDevice//»º´æµÄ
    if (cacheDevices != null)
    { for (int i = 0; i < cacheDevices.length; i++) {
    remoteDevices.put(cacheDevices.getBluetoothAddress(), cacheDevices); //¹þʲ±í
    }
    }
    RemoteDevice[] preDevices = discoveryAgent.retrieveDevices(DiscoveryAgent.PREKNOWN); // class RemoteDevice//ÒÑÖªµÄ
    if (preDevices != null)
    { for (int i = 0; i < preDevices.length; i++) {
    remoteDevices.put(cacheDevices.getBluetoothAddress(),cacheDevices); //¹þʲ±í ÕâÀïºÃÏñд´íÁË Ó¦¸ÃÊÇpreDevices
    }
    } // ÔÚ»º´æµÄºÍÒÑÖªµÄÉ豸Éϲéѯ¡°·þÎñ¡±,º¯Êý¶¨ÒåÔÚÏÂÃæ
    searchServices(remoteDevices);
    if (serviceRecord != null)// ÕÒµ½·µ»Ø
    return; // ¿ªÊ¼ËÑË÷É豸
    discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);//ÕâÀïµÄthisÊÇÖ¸±¾À࣮µ±È»ÎÒÃÇÒªÔÚ±¾ÀàʵÏÖDiscoveryListener½Ó¿Ú£® // ÔÚËÑË÷µ½µÄÉ豸Éϲéѯ·þÎñ
    searchServices(remoteDevices);//È¥ÏÂÃæ¿´¿´Õâ¸öº¯ÊýµÄʵÏÖ
    remoteDevices.clear();
    } catch (BluetoothStateException e) {
    e.printStackTrace();
    }
    if (serviceRecord != null)
    { notify();
    }
    else { }
    }
    private void searchServices(Hashtable remotes) throws BluetoothStateException {
    // UUID[] UUIDs = new UUID[1]; UUIDs[1] = new UUID(uuidString, false); UUID UUIDs[0] = new UUID(0x0003);
    for (Enumeration e = remotes.keys(); e.hasMoreElements();)
    {
    String key = (String) e.nextElement();
    RemoteDevice remoteDevice = (RemoteDevice) remotes.get(key);

    discoveryAgent.searchServices(null, UUIDs, remoteDevice, this);
    }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    public void deviceDiscovered(RemoteDevice device, DeviceClass cod)
    { deviceDiscoverd();
    remoteDevices.put(device.getBluetoothAddress(), device);
    }
    //////////////////////////////////
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord)
    { // ·¢ÏÖ¸ÐÐËȤµÄ·þÎñ£¬ÕâÀïÖ±½ÓʹÓõÚÒ»¸ö
    if (servRecord == null || servRecord.length == 0)
    { url = null; serviceRecord = null; return;
    }
    url = serviceRecord.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
    } ////////////////////////////////////////////////////////////////////////////////////////////////////
    public void inquiryCompleted(int discType)
    { //É豸²éѯÍê³É
    try
    {
    searchServices(remoteDevices); //¿ªÊ¼²éѯ·þÎñÁË£¬
    }
    catch (BluetoothStateException e)
    {
    e.printStackTrace();
    }
    remoteDevices.clear();
    }


    public void serviceSearchCompleted(int transID, int respCode)
    {//·þÎñ²éѯÍê³É
    synchronized (this)
    { //ͬ²½
    notifyAll(); //·þÎñ²éѯÍê³Éºó »á½ÐÐÑËùÓÐÏ̡߳£
    }
    } ////////////////////////////////////////////////////////////////////////////////////////////////////
    public void close()
    {
    Object writeWorkTh;
    Object in;
    Object out;
    Object conn;
    Object readWorkTh;
    boolean exitFlag;
    try
    { exitFlag = true; synchronized (this)
    { notify(); //ÕâÒ²Óл½ÐÑ µ«ÊDz»ÖªµÀ¾ßÌå×öʲôÓõģ¿Çë½ÌÒ»ÏÂ
    }
    if (writeWorkTh != null)
    {
    synchronized (writeWorkTh)
    { writeWorkTh.notify(); //ÕâÒ²Óл½ÐÑ£¬Çë½Ì£¡
    }
    }
    if (in != null)
    {
    in.close();
    }
    if (out != null)
    {
    out.close();
    }
    if (conn != null) conn.close();
    if (readWorkTh != null)
    {
    readWorkTh.join();
    }
    if (writeWorkTh != null) writeWorkTh.join();
    if (th != null) th.join();
    } catch (IOException e)
    { e.printStackTrace(); }
    catch (InterruptedException e) { e.printStackTrace(); }
    } ////////////////////////////////////////////////////////////////////////////////////////////////////
    public void send(String str)
    { ////·¢ËÍÐÅÏ¢ Íⲿ¶ÔÏó»áµ÷Óô˷½·¨
    if (writeWorkTh == null) return;
    sendText = str;
    synchronized (writeWorkTh)
    { writeWorkTh.notify(); //Ö¸¶¨Ï̻߳½ÐÑ ±ð˯ÁË ¸É»îÁË
    }
    } ////////////////////////////////////////////////////////////////////////////////////////////////////
    class ReadWorkThread extends Thread
    {
    public void run() {
    try
    {
    while (!exitFlag)
    {
    String str = in.readUTF();
    if (str != null)
    {
    }
    }
    } catch (IOException e)
    {
    }
    }
    } //////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
    class WriteWorkThread extends Thread
    { // @Override
    public void run(){
    try {
    while (!exitFlag)
    { synchronized (this)
    {
    try
    { wait();//ÕâµÈ´ýÒ»ÏÂ
    } catch (InterruptedException e)
    { e.printStackTrace();
    }
    if (exitFlag)// ¿ÉÄÜÒòΪ¹Ø±Õ²Ù×÷±»´ò¶Ï
    break;
    if (sendText != null) out.writeUTF(sendText);
    }////
    }
    } catch (IOException e)
    {
    }
    }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    public void startSearch() {

    }
    }

    I am getting 2 error
    C:\WTK25\apps\3f59c924faf\src\BTClient.java:28: ';' expected
    java.util.Hashtable String url;
    ^
    C:\WTK25\apps\3f59c924faf\src\BTClient.java:28: <identifier> expected
    java.util.Hashtable String url;
    i am not able to debug.....
    Dharanya, Dec 26, 2011
    #1
    1. Advertising

  2. Dharanya

    Dharanya

    Joined:
    Dec 26, 2011
    Messages:
    2
    oh sad..what u did to rectify??? pls help me...
    Dharanya, Dec 28, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Um9nZXI=?=

    balloon message and wireless connection problems pls help

    =?Utf-8?B?Um9nZXI=?=, Jun 22, 2005, in forum: Wireless Networking
    Replies:
    8
    Views:
    2,015
    =?Utf-8?B?SW5zdGFsbGVy?=
    Jun 27, 2005
  2. FireFerum

    Wireless XP Pro to 2k3 help pls

    FireFerum, Oct 4, 2005, in forum: Wireless Networking
    Replies:
    0
    Views:
    371
    FireFerum
    Oct 4, 2005
  3. olabanji  timothy

    pls, help.. i need a number..pls

    olabanji timothy, Sep 9, 2003, in forum: MCSE
    Replies:
    7
    Views:
    802
  4. xiaobb03@gmail.com
    Replies:
    0
    Views:
    755
    xiaobb03@gmail.com
    Mar 13, 2008
  5. irfansmith@gmail.com

    URGENT - Pls help...pls recommend - laptop purchase

    irfansmith@gmail.com, Aug 15, 2008, in forum: Computer Information
    Replies:
    2
    Views:
    642
    trouble
    Aug 16, 2008
Loading...

Share This Page