0

Hi
i want to use mobile device bluetooth , i use this code but there is probleam with this method getDiscoveryAgent() . this error shown :

Null pointer java/lang/nullpointer exeption

this is my code :

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Vector;
import java.io.*;
import javax.bluetooth.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

/**
 * @author mahdi
 */
public class Midlet extends MIDlet implements CommandListener {

    LocalDevice local = null;
    DiscoveryAgent agent = null;
    List activeDevices = new List("Active Devices", List.IMPLICIT);
    Display display;

    public void startApp() {
        display = Display.getDisplay(this);
        doDeviceDiscovery();
        display.setCurrent(activeDevices);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
    }

    public void doDeviceDiscovery() {
        try {
            local = LocalDevice.getLocalDevice();
        } catch (BluetoothStateException ex) {
            ex.printStackTrace();
        }
        agent = local.getDiscoveryAgent();
    }
}

and this is out put on netbeans :

Smart card communication error 0x80100017
The specified reader is not currently available for use
Using Untrusted simulated domain
"Series 40 5th Edition SDK, Feature Pack 1" Instance #6500500 Ready for Future Connections
"Series 40 5th Edition SDK, Feature Pack 1" Connection Terminated

can any body help me ?
thanks

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by newbi in jme
0

hi mahdi68
public class Midlet extends MIDlet implements CommandListener
u should write
public class Midlet extends MIDlet implements CommandListener,DiscoveryListener {
and use this one for device discovery

try {
            if (!agent.startInquiry(DiscoveryAgent.GIAC, this)) {
            // Inquiry not started, error handling code here
            }
            } catch (BluetoothStateException bse) {
            // Error handling code here
            }
and there are two method u should use 
deviceDiscovered
inquiryCompleted
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.