hi im making a bluetooth client using netbeans IDE 6.5 the code is


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

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.bluetooth.BluetoothStateException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

/**addingby me
*
*/
import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeExcepti on;
import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDletStateChangeExcepti on;
import java.io.IOException;


/**
* @author Tariq
*/
public class VisualMIDlet extends MIDlet implements CommandListener {
LocalDevice local;
DiscoveryAgent agent;
boolean complete;
int accessCode;
DiscoveryListener listener;
StreamConnection connection;
ServiceRecord record;
int requiredSecurity;
private boolean midletPaused = false;

//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">
private Form form;
private Form form1;
private Command okCommand;
private Command exitCommand;
private Command backCommand;
//</editor-fold>

/**
* The VisualMIDlet constructor.
*/
public VisualMIDlet() {
}

//<editor-fold defaultstate="collapsed" desc=" Generated Methods ">
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">
/**
* Initilizes the application.
* It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
*/
private void initialize() {
// write pre-initialize user code here

// write post-initialize user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">
/**
* Performs an action assigned to the Mobile Device - MIDlet Started point.
*/
public void startMIDlet() {
// write pre-action user code here
switchDisplayable(null, getForm());
// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">
/**
* Performs an action assigned to the Mobile Device - MIDlet Resumed point.
*/
public void resumeMIDlet() {
// write pre-action user code here

// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">
/**
* Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
* @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
* @param nextDisplayable the Displayable to be set
*/
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
// write pre-switch user code here
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
// write post-switch user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">
/**
* Called by a system to indicated that a command has been invoked on a particular displayable.
* @param command the Command that was invoked
* @param displayable the Displayable where the command was invoked
*/
public void commandAction(Command command, Displayable displayable) {
// write pre-action user code here
if (displayable == form) {
if (command == exitCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
} else if (command == okCommand) {
// write pre-action user code here
// retrieve the discovery agent
agent = local.getDiscoveryAgent();
try {
// place the device in inquiry mode
complete = agent.startInquiry(accessCode, listener);
} catch (BluetoothStateException ex) {
ex.printStackTrace();
}
// return an array of pre-known devices
RemoteDevice[] devices =agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
// (assuming we have the service record)
// use record to retrieve a connection URL
String url =record.getConnectionURL(requiredSecurity,false);
try {
// open a connection to the server
connection = (StreamConnection) Connector.open(url);
} catch (IOException ex) {
ex.printStackTrace();
}
// Send/receive data
try {
byte buffer[] = new byte[100];
String msg = "hello there, server";
InputStream is = connection.openInputStream();
OutputStream os = connection.openOutputStream();
// send data to the server
os.write(msg.getBytes());
// read data from the server
is.read(buffer);
connection.close();
} catch(IOException e) {
e.printStackTrace();
}

switchDisplayable(null, getForm1());
// write post-action user code here
}
} else if (displayable == form1) {
if (command == backCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
}
}
// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">
/**
* Returns an initiliazed instance of form component.
* @return the initialized component instance
*/
public Form getForm() {
if (form == null) {
// write pre-init user code here
form = new Form("form");
form.addCommand(getOkCommand());
form.addCommand(getExitCommand());
form.setCommandListener(this);
// write post-init user code here
}
return form;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: form1 ">
/**
* Returns an initiliazed instance of form1 component.
* @return the initialized component instance
*/
public Form getForm1() {
if (form1 == null) {
// write pre-init user code here
form1 = new Form("form1");
form1.addCommand(getBackCommand());
form1.setCommandListener(this);
// write post-init user code here
}
return form1;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">
/**
* Returns an initiliazed instance of okCommand component.
* @return the initialized component instance
*/
public Command getOkCommand() {
if (okCommand == null) {
// write pre-init user code here
okCommand = new Command("Ok", Command.OK, 0);
// write post-init user code here
}
return okCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">
/**
* Returns an initiliazed instance of exitCommand component.
* @return the initialized component instance
*/
public Command getExitCommand() {
if (exitCommand == null) {
// write pre-init user code here
exitCommand = new Command("Exit", Command.EXIT, 0);
// write post-init user code here
}
return exitCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">
/**
* Returns an initiliazed instance of backCommand component.
* @return the initialized component instance
*/
public Command getBackCommand() {
if (backCommand == null) {
// write pre-init user code here
backCommand = new Command("Back", Command.BACK, 0);
// write post-init user code here
}
return backCommand;
}
//</editor-fold>

/**
* Returns a display instance.
* @return the display instance.
*/
public Display getDisplay () {
return Display.getDisplay(this);
}

/**
* Exits MIDlet.
*/
public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}

/**
* Called when MIDlet is started.
* Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
*/
public void startApp() {
if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();
}
midletPaused = false;
}

/**
* Called when MIDlet is paused.
*/
public void pauseApp() {
midletPaused = true;
}

/**
* Called to signal the MIDlet to terminate.
* @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
*/
public void destroyApp(boolean unconditional) {
}

}



when irun that program the i show phon put i press find
the erreo happen is


java.lang.NullPointerException
at VisualMIDlet.commandAction(VisualMIDlet.java:133)
at javax.microedition.lcdui.Display$DisplayAccessor.c ommandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImp l.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEven t(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEv ent(AutomatedEventHandler.java:670)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEvent Handler.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEvent Handler.run(+57)


please i need your help