We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,301 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

j2me:probleam with getDiscoveryAgent()

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
1 Week
Discussion Span
2 Years Ago
Last Updated
2
Views
mahdi68
Junior Poster in Training
95 posts since Jun 2009
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 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
newbi in jme
Newbie Poster
2 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0579 seconds using 2.69MB