0

I all.

I am trying to make a program that connects 2 mobile phones, and send a string to the server mobile, and then sends the thread back.
I have tested it in netbeans, and it looks like it discoveres the device. but then I get an error:

Address: 0123456789AF
Name: WirelessToolkit
Starting device inquiry...
Device Inquiry Completed.
Bluetooth Devices:
1. 0000000DECAF (WirelessToolkit)

Searching for service...
java.lang.NullPointerException
at com.sun.kvem.jsr082.bluetooth.DataL2CAPReaderWriter.<init>(DataL2CAPReaderWriter.java:50)
at com.sun.kvem.jsr082.bluetooth.SDPClient$SDPTransport.start(SDPClient.java:283)
at com.sun.kvem.jsr082.bluetooth.SDPClient.openTransport(SDPClient.java:102)
at com.sun.kvem.jsr082.bluetooth.SDPClient.open(SDPClient.java:183)
at com.sun.kvem.jsr082.bluetooth.SDPClient.<init>(SDPClient.java:68)
at com.sun.kvem.jsr082.bluetooth.ServiceSearcher.start(ServiceSearcher.java:76)
at com.sun.kvem.jsr082.bluetooth.DiscoveryAgentImpl.searchServices(DiscoveryAgentImpl.java:225)
at javax.bluetooth.DiscoveryAgent.searchServices(DiscoveryAgent.java:259)
at SampleSPPClient.main(SampleSPPClient.java:96)
at SPP_midlet.listAction(SPP_midlet.java:147)
at SPP_midlet.commandAction(SPP_midlet.java:95)
at javax.microedition.lcdui.List.callKeyPressed(List.java:818)
at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(Display.java:2209)
at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(Display.java:2952)
at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(DefaultEventHandler.java:249)
at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(AutomatedEventHandler.java:620)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(DefaultEventHandler.java:699)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(DefaultEventHandler.java:608)

Does anyone know what this means. I can post the code if needed.
Hope someone can help me.

kind regards Michael.

2
Contributors
17
Replies
20
Views
9 Years
Discussion Span
Last Post by Dancealot
Featured Replies
  • 1

    Dunno what could cause such thing. OK, in attachments are source files as I have them. They working fine. Just place these files in the project "src" folder to replace what ever you have there and run them. Let me know if you getting any errors etc. Read More

  • 2

    Right click on project folder -> Properties -> in Category select Application Descriptor -> on right side of the window click on the MIDlets. Here you need to point NetBeans to MIDlet in your project. Click Add and find location of BlueChewMIDlet.java. Compile and run Read More

0

Sure. The code for the client is here:

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

/**
 *
 * @author MMA
 */
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Vector;

 
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;
 
/**
* A simple SPP client that connects with an SPP server
*/
public class SampleSPPClient implements DiscoveryListener{
    
    //object used for waiting
    private static Object lock=new Object();
    
    //vector containing the devices discovered
    private static Vector vecDevices=new Vector();
    
    private static String connectionURL=null;
 
    public static void main(String[] args) throws IOException {
        
        SampleSPPClient client=new SampleSPPClient();
        
        //display local device address and name
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        System.out.println("Address: "+localDevice.getBluetoothAddress());
        System.out.println("Name: "+localDevice.getFriendlyName());
        
        //find devices
        DiscoveryAgent agent = localDevice.getDiscoveryAgent();
      
        System.out.println("Starting device inquiry...");
        agent.startInquiry(DiscoveryAgent.GIAC, client);
        
        try {
            synchronized(lock){
                lock.wait();
            }
        } 
        catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        
        System.out.println("Device Inquiry Completed. ");
        
        //print all devices in vecDevices
        int deviceCount=vecDevices.size();
        
        if(deviceCount <= 0){
            System.out.println("No Devices Found .");
            System.exit(0);
        }
        else{
            //print bluetooth device addresses and names in the format [ No. address (name) ]
            System.out.println("Bluetooth Devices: ");
            for (int i = 0; i <deviceCount; i++) {
                RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(i);
                System.out.println((i+1)+". "+remoteDevice.getBluetoothAddress()+" ("+remoteDevice.getFriendlyName(true)+")");
            }
        }
        
/*        System.out.print("Choose Device index: ");
        BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));
        
        String chosenIndex=bReader.readLine();
        int index=Integer.parseInt(chosenIndex.trim());*/
        
        //check for spp service
        RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(0);
        UUID[] uuidSet = new UUID[1];
        uuidSet[0]=new UUID("1101",false);
        
        System.out.println("\nSearching for service...");
        agent.searchServices(null,uuidSet,remoteDevice,client);
        
        try {
            synchronized(lock){
                lock.wait();
            }
        } 
        catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        if(connectionURL==null){
            System.out.println("Device does not support Simple SPP Service.");
            System.exit(0);
        }
        
        //connect to the server and send a line of text
        StreamConnection streamConnection=(StreamConnection)Connector.open(connectionURL);
        
        //send string
        OutputStream outStream=streamConnection.openOutputStream();
        
            outStream.write(1);
            outStream.flush();            
        
        
        
        
        //read response
        InputStream inStream=streamConnection.openInputStream();
        int input = inStream.read();
/*        BufferedReader bReader2=new BufferedReader(new InputStreamReader(inStream));
        String lineRead=bReader2.readLine();*/
        System.out.println(input);
        
                
    }//main
    
    //methods of DiscoveryListener
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
        //add the device to the vector
        if(!vecDevices.contains(btDevice)){
            vecDevices.addElement(btDevice);
        }
    }
 
    //implement this method since services are not being discovered
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
        if(servRecord!=null && servRecord.length>0){
            connectionURL=servRecord[0].getConnectionURL(0,false);
        }
        synchronized(lock){
            lock.notify();
        }
    }
 
    //implement this method since services are not being discovered
    public void serviceSearchCompleted(int transID, int respCode) {
        synchronized(lock){
            lock.notify();
        }
    }
 
    
    public void inquiryCompleted(int discType) {
        synchronized(lock){
            lock.notify();
        }
        
    }//end method
    
    
    
}
0

server is:

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

/**
 *
 * @author MMA
 */
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

 
import javax.bluetooth.*;
import javax.microedition.io.*;
 
/**
* Class that implements an SPP Server which accepts single line of
* message from an SPP client and sends a single line of response to the client.
*/
public class SampleSPPServer {
    
    //start server
    private void startServer() throws IOException{
 
        //Create a UUID for SPP
        UUID uuid = new UUID("1101", true);
        //Create the servicve url
        String connectionString = "btspp://localhost:" + uuid +";name=Sample SPP Server";
        
        //open server url
        StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open( connectionString );
        
        //Wait for client connection
        System.out.println("\nServer Started. Waiting for clients to connect...");
        StreamConnection connection=streamConnNotifier.acceptAndOpen();
 
        RemoteDevice dev = RemoteDevice.getRemoteDevice(connection);
        System.out.println("Remote device address: "+dev.getBluetoothAddress());
        System.out.println("Remote device name: "+dev.getFriendlyName(true));
        
        //read string from spp client
        InputStream inStream=connection.openInputStream();
        int input = inStream.read();
        /*BufferedReader bReader=new BufferedReader(new InputStreamReader(inStream));
        String lineRead=bReader.readLine();*/
        System.out.println(input);
        
        //send response to spp client
        OutputStream outStream=connection.openOutputStream();
        outStream.write(input);
   /*     PrintWriter pWriter=new PrintWriter(new OutputStreamWriter(outStream));
        pWriter.write("Response String from SPP Server\r\n");
        pWriter.flush();
 
        pWriter.close();*/
        
        outStream.flush();
        streamConnNotifier.close();
 
    }
 
 
    public static void main(String[] args) throws IOException {
        
        //display local device address and name
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        System.out.println("Address: "+localDevice.getBluetoothAddress());
        System.out.println("Name: "+localDevice.getFriendlyName());
        
        SampleSPPServer sampleSPPServer=new SampleSPPServer();
        sampleSPPServer.startServer();
        
    }
}
0

You need to sort the basic. This is supposed to be application for mobile devices. Therefore we do not use main() method but go with MIDlet and its three subclasses startApp(), pauseApp() and destroyApp(). Have look on this example of BT communication from Jonathan Knudsen (download chap 20)

0

Hi again.

thx for the great program from Jonathan Knudsen. I have a problem though. When i import it, there are a lot of red underlinings in the files, (src folder). The program runs, but it is very hard to find out what is what for me then. Did I import it wrong or do something other wrong. I use netbeans btw. Hope you can help me. Kind regards Michael.

0

Red underlining means either there is an error or you missing libraries. In your case it is the second option as the program is OK. Do you have Mobility pack installed on your NetBeans?

As for application

  • BlueChewMIDlet provides user interface and coordinate the remaining objects of the application.
  • BlueChewFinder provides device discovery, the list of found devices is stored in Vector
  • BlueChewServer is the service itself.
  • BlueChewService - compact represenatation of ServiceRecord, it holds name, address and connection string
  • Log - keeps track of a list of messages (Jonathan used it for debugging)
0

thx for the explanation.

I think I have mobility pack installed. I am able to create a project using mobility as project category. The strange thing is that the project compiles without a problem, so that is why I dont understand all the red underlinings.

0

Do right click on project folder kb-ch20 select Properties from the bottom of the menu. In Properties check platform settings select in Category -> Platform and check if it is pointing to your WTK or is requesting something from outside (correct it if wrong).
Close this dialogue window. Expand project folder view kb-ch20 -> Project Configurations -> Default Configuration -> Resources and delete the pointer to non-existing resource location on D:\ drive (looks like Jonathan had something there and forgot to remove it)

Let me know what it does now...

0

It is pointing to my sun wireless toolkit 2.5, so that should be ok. Under the default configuration -> resources, there is only resources, so I dont think that it's pointing to anything on the d drive here.

0

OK this getting interesting as I had to correct WTK and remove resource. What you get when you right click on project folder and select Resolve Reference Problems (second option from bottom if there any reference problems)?

0

that option is not there. (proporly meaning that there are no reference problem ?).
I could imagine that the error is that I imported it wrong or something. The first line in the code (import java.io.*) has a "!" to the left of it. And I think that it is strange that that line shouldn't work.

1

Dunno what could cause such thing. OK, in attachments are source files as I have them. They working fine. Just place these files in the project "src" folder to replace what ever you have there and run them. Let me know if you getting any errors etc.

Attachments
import java.io.IOException;
import java.util.Vector;

import javax.bluetooth.*;

public class BlueChewFinder implements DiscoveryListener {
  private BlueChewMIDlet mBlueChewMIDlet;
  
  private Vector mNewServices;
  private Vector mServices;
  
  private boolean mSearching;
  private int mPendingServiceSearches;
  
  private boolean mTrucking;
  
  public BlueChewFinder(BlueChewMIDlet midlet) {
    mBlueChewMIDlet = midlet;
    mNewServices = new Vector();
    mServices = new Vector();
    mSearching = false;
    mPendingServiceSearches = 0;
    mTrucking = true;
  }
  
  public void start() {
    // Start looking for other devices.
    try {
      LocalDevice bt = LocalDevice.getLocalDevice();
      DiscoveryAgent da = bt.getDiscoveryAgent();
      boolean success = da.startInquiry(DiscoveryAgent.GIAC,
          this);
      mSearching = true;
    }
    catch (BluetoothStateException bse) {
      Log.log("start() threw " + bse);
    }
  }
  
  public void stop() {
    // Shut down any running inquiries.
    try {
      mTrucking = false;
      LocalDevice bt = LocalDevice.getLocalDevice();
      DiscoveryAgent da = bt.getDiscoveryAgent();
      da.cancelInquiry(this);
    }
    catch (BluetoothStateException bse) {
      Log.log("stop() threw " + bse);
    }
  }
  
  public String getURL(int i) {
    BlueChewService bcs = (BlueChewService)
        mServices.elementAt(i);
    String url = bcs.getURL();
    return url;
  }

  // DiscoveryListener methods
  
  public void deviceDiscovered(RemoteDevice remoteDevice,
      DeviceClass cod) {
    try {
      // Kick off a service search for that device.
      LocalDevice bt = LocalDevice.getLocalDevice();
      DiscoveryAgent da = bt.getDiscoveryAgent();
      
      UUID[] uuidSet = { BlueChewService.BLUECHEW_UUID };
      
      mPendingServiceSearches++;
      da.searchServices(
          null,
          uuidSet,
          remoteDevice,
          this);
    }
    catch (IOException ioe) {
      Log.log("deviceDiscovered(): " + ioe);
    }
    catch (Throwable t) {
      Log.log("deviceDiscovered(): " + t);
    }
  }
  
  public void inquiryCompleted(int discType) {
    mSearching = false;
  }
  
  public void servicesDiscovered(int transID,
      ServiceRecord[] servRecord) {
    for (int i = 0; i < servRecord.length; i++) {
      try {
        RemoteDevice bt = servRecord[i].getHostDevice();
        String name = bt.getFriendlyName(false);
        String address = bt.getBluetoothAddress();
        String url = servRecord[i].getConnectionURL(
            ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
        BlueChewService bcs = new BlueChewService(
            name, address, url);
        mNewServices.addElement(bcs);
      }
      catch (BluetoothStateException bse) {
        Log.log("servicesDiscovered(): " + bse);
      }
      catch (IOException ioe) {
        Log.log("servicesDiscovered(): " + ioe);
      }
    }
  }
  
  public void serviceSearchCompleted(int transID,
      int respCode) {
    mPendingServiceSearches--;
    
    if (mSearching == false && mPendingServiceSearches == 0) {
      reconcile();

      try { Thread.sleep(1000); }
      catch (InterruptedException ie) {}
      
      if (mTrucking == true)
        start();
    }
  }
  
  // BlueChewFinder methods
  
  public synchronized void reconcile() {
    // Remove items from mServices that are not in mNewServices.
    for (int i = 0; i < mServices.size(); i++) {
      BlueChewService bcs =
          (BlueChewService)mServices.elementAt(i);
      if (contains(mNewServices, bcs) == false) {
        mServices.removeElement(bcs);
        mBlueChewMIDlet.serviceRemoved(bcs, i);
      }
    }
    
    // Add items from mNewServices to mServices.
    for (int i = 0; i < mNewServices.size(); i++) {
      BlueChewService bcs =
          (BlueChewService)mNewServices.elementAt(i);
      if (contains(mServices, bcs) == false) {
        mServices.addElement(bcs);
        mBlueChewMIDlet.serviceAdded(bcs);
      }
    }
    
    mNewServices.removeAllElements();
  }
  
  // Compares for equality, not the same actual object.
  private boolean contains(Vector v, Object o) {
    boolean contained = false;
    
    for (int i = 0; i < v.size(); i++) {
      Object oc = v.elementAt(i);
      if (oc.equals(o))
        contained = true;
    }
    return contained;
  }
}
import java.io.*;
import java.util.*;

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

import javax.bluetooth.*;

public class BlueChewMIDlet
    extends MIDlet
    implements CommandListener, Runnable {
  private BlueChewServer mBlueChewServer;
  private BlueChewFinder mBlueChewFinder;
  
  private Form mSendForm;
  private TextField mMessageField;
  private ChoiceGroup mDestinations;
  private Command mSendCommand, mBackCommand, mExitCommand;
  
  public void startApp() {
    createUI();
    setupConnections();
    Display.getDisplay(this).setCurrent(mSendForm);
  }
  
  private void createUI() {
    if (mSendForm != null) return;
    
    mSendCommand = new Command("Send", Command.SCREEN, 0);
    mBackCommand = new Command("Back", Command.BACK, 0);
    mExitCommand = new Command("Exit", Command.EXIT, 0);
    
    mSendForm = new Form("BlueChewMIDlet");
    mMessageField = new TextField("Message:", "Hello, nurse!",
        512, TextField.ANY);
    mDestinations = new ChoiceGroup("Destinations",
        ChoiceGroup.MULTIPLE);
    mSendForm.append(mMessageField);
    mSendForm.append(mDestinations);
    mSendForm.addCommand(mSendCommand);
    mSendForm.addCommand(mExitCommand);
    mSendForm.setCommandListener(this);
  }

  private void setupConnections() {
    mBlueChewServer = new BlueChewServer(this);
    mBlueChewServer.start();

    mBlueChewFinder = new BlueChewFinder(this);
    mBlueChewFinder.start();
  }
  
  public void pauseApp() {}
  
  public void destroyApp(boolean unconditional) {
    mBlueChewServer.stop();
    mBlueChewFinder.stop();
  }
  
  public void commandAction(Command c, Displayable s) {
    if (c.getCommandType() == Command.EXIT) {
      destroyApp(true);
      notifyDestroyed();
    }
    else if (c == mSendCommand) {
      Form waitForm = new Form("Sending...");
      Display.getDisplay(this).setCurrent(waitForm);
      Thread t = new Thread(this);
      t.start();
    }
    else if (c == mBackCommand) {
      Display.getDisplay(this).setCurrent(mSendForm);
    }
  }
  
  // Runnable method
  
  public void run() {
    Vector urls = new Vector();
    
    // Synchronize so reconcile() won't run
    // at the same time.
    synchronized(mBlueChewFinder) {
      int n = mDestinations.size();
      boolean[] flags = new boolean[n];
      mDestinations.getSelectedFlags(flags);
      for (int i = 0; i < n; i++) {
        if (flags[i] == true) {
          String url = mBlueChewFinder.getURL(i);
          urls.addElement(url);
        }
      }
    }
    
    for (int i = 0; i < urls.size(); i++) {
      String url = (String)urls.elementAt(i);
      try { runURL(url); }
      catch (IOException ioe) {
        Log.log("BlueChewMIDlet.run(): " + ioe);
      }
    }
    Display.getDisplay(this).setCurrent(mSendForm);
  }
    
  private void runURL(String url) throws IOException {
    StreamConnection sc = null;
    DataOutputStream dataOut = null;
    
    try {
      sc = (StreamConnection)
          Connector.open(url);
      dataOut = new DataOutputStream(
          sc.openOutputStream());
      LocalDevice bt = LocalDevice.getLocalDevice();
      String from = bt.getFriendlyName() + ":" +
          bt.getBluetoothAddress();
      dataOut.writeUTF(from);
      dataOut.writeUTF(mMessageField.getString());
    }
    finally {
      try { if (dataOut != null) dataOut.close(); }
      catch (IOException ioe) {}
      try { if (sc != null) sc.close(); }
      catch (IOException ioe) {}
    }
  }
  
  // BlueChewServer callback
  
  public void messageReceived(String from, String message) {
    int layout = Item.LAYOUT_NEWLINE_AFTER;
    StringItem si;
    Form messageForm = new Form("Message");
    si = new StringItem("From:", from);
    si.setLayout(layout);
    messageForm.append(si);
    si = new StringItem("Message:", message);
    si.setLayout(layout);
    messageForm.append(si);
    messageForm.addCommand(mBackCommand);
    messageForm.setCommandListener(this);
    Display.getDisplay(this).setCurrent(messageForm);
  }
  
  // BlueChewFinder callbacks
  
  public void serviceAdded(BlueChewService bcs) {
    String s = bcs.getName() + ":" + bcs.getAddress();
    mDestinations.append(s, null);
  }
  
  public void serviceRemoved(BlueChewService bcs, int i) {
    mDestinations.delete(i);
  }
}
import java.io.*;

import javax.microedition.io.*;

import javax.bluetooth.*;

public class BlueChewServer implements Runnable {
  private BlueChewMIDlet mBlueChewMIDlet;
  
  private boolean mTrucking;
  private StreamConnectionNotifier mNotifier;
  
  public BlueChewServer(BlueChewMIDlet midlet) {
    mBlueChewMIDlet = midlet;
  }
  
  public void start() {
    mTrucking = true;
    Thread t = new Thread(this);
    t.start();
  }
  
  public void stop() {
    mTrucking = false;
    try { if (mNotifier != null) mNotifier.close(); }
    catch (IOException ioe) {}
  }    
  
  public void run() {
    // Make sure we're discoverable.
    try {
      LocalDevice bt = LocalDevice.getLocalDevice();
      bt.setDiscoverable(DiscoveryAgent.GIAC);
    }
    catch (BluetoothStateException bse) {
      Log.log("BlueChewServer.run(): " + bse);
    }

    // Start up the server.
    try {
      UUID uuid = BlueChewService.BLUECHEW_UUID;

      String cs = "btspp://localhost:" + uuid.toString()
          + ";name=BlueChew";

      mNotifier =
          (StreamConnectionNotifier)Connector.open(cs);
      
      while (mTrucking) {
        // Get the next incoming connection.
        StreamConnection sc = mNotifier.acceptAndOpen();
        
        // Service inline. We could spawn off a thread for
        // each but it seems unnecessary for this type of
        // application.
        DataInputStream dataIn = new DataInputStream(
            sc.openInputStream());
        String from = dataIn.readUTF();
        String message = dataIn.readUTF();
        mBlueChewMIDlet.messageReceived(from, message);
        dataIn.close();
        sc.close();
      }
    }
    catch (BluetoothStateException bse) {
      Log.log("BlueChewServer.run(): " + bse);
    }
    catch (IOException ioe) {
      if (mTrucking == true)
        Log.log("BlueChewServer.run(): " + ioe);
    }
  }
}
import javax.bluetooth.UUID;

public class BlueChewService {
  public static final UUID BLUECHEW_UUID = 
      new UUID("F0E0D0C0B0A000908070605040302010", false);
  
  private String mName;
  private String mAddress;
  private String mURL;
  
  public BlueChewService(String name, String address,
      String url) {
    mName = name;
    mAddress = address;
    mURL = url;
  }
  
  public String getName() { return mName; }
  public String getAddress() { return mAddress; }
  public String getURL() { return mURL; }
  
  public boolean equals(Object o) {
    if (o == this) return true;
    if (o instanceof BlueChewService == false) return false;
    
    BlueChewService bcs = (BlueChewService)o;
    if (bcs.getName().equals(mName) == false) return false;
    if (bcs.getAddress().equals(mAddress) == false)
      return false;
    if (bcs.getURL().equals(mURL) == false) return false;

    return true;
  }    
  
  public String toString() {
    return "[BlueChewService:" + mName + ":" + mAddress
        + ":" + mURL + "]";
  }
}
import java.util.Vector;

import javax.microedition.lcdui.*;

import javax.bluetooth.*;

public class Log {
  private static Vector sLines;
  
  private static Form sLogForm;
  
  public static void log(String s) {
    if (sLines == null) sLines = new Vector();
    
    // Prepend address information.
    try {
      LocalDevice bt = LocalDevice.getLocalDevice();
      String address = bt.getBluetoothAddress();
      s = address + ": " + s;
    }
    catch (BluetoothStateException bse) {}

    sLines.addElement(s);
    logToForm(s);
    System.out.println(s);
  }
  
  public static Form getLogForm() {
    if (sLogForm != null) return sLogForm;
    
    sLogForm = new Form("Log");
    
    for (int i = 0; i < sLines.size(); i++) {
      String s = (String)sLines.elementAt(i);
      logToForm(s);
    }
    return sLogForm;
  }
  
  protected static void logToForm(String s) {
    if (sLogForm == null) return;
    
    int layout = Item.LAYOUT_2 | Item.LAYOUT_NEWLINE_AFTER;
    StringItem si = new StringItem(null, s);
    si.setLayout(layout);
    //sLogForm.insert(0, si);
    sLogForm.append(si);
  }
}
0

thanks for the files. The folder that I should put them in, is that \projectname\build\compiled\src. I have no files there. I have the 5 files with the same name, but with .class under, \ImportedProject-Kb-ch201\build\compiled.

0

I have now made a new project, and I have copied the files to the src folder, and it looks like there are no errors (hurraa :) ), but when I try to run it, nothing happens. Is that because I have to make a midlet that activates it or something ?

2

Right click on project folder -> Properties -> in Category select Application Descriptor -> on right side of the window click on the MIDlets. Here you need to point NetBeans to MIDlet in your project. Click Add and find location of BlueChewMIDlet.java. Compile and run

Votes + Comments
The Phone Guru
0

Perfect mate. That did the trick. I will have a look at the application now. Thx a lot mate.

This question has already been answered. 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.