Hello! I am new in J2ME and I had a project about how to build a communication system by java codes.I just need to know the problem I have in my code such that I get an error when execute it through console.The error is:
javax.microedition.io.ConnectionNotFoundException:The requested Protocol doesnot exist btspp://localhost:1101;name: program

package doctor;
import java.io.*;
import javax.microedition.bluetooth.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
//import com.rococosoft.io.*;
public class Program extends MIDlet implements CommandListener
{
private Display display;
private TextBox textBox1;
private Command entryCommand;
private Command exitCommand;
public void startApp()
{display=Display.getDisplay(this);
 entryCommand=new Command("OK", Command.SCREEN, 1);
 exitCommand=new Command("Quit", Command.SCREEN, 1);
 textBox1=new TextBox("How application works..", "This application helps to send an alert ", 256, 0);
 textBox1.addCommand(entryCommand);
 textBox1.addCommand(exitCommand);
 textBox1.setCommandListener(this);
 display.setCurrent(textBox1);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command choice,Displayable displayable)
{if(choice==exitCommand)
 {destroyApp(false);
  notifyDestroyed();
 }
 else
 {      
            try {
                Delp();
                } catch (IOException ex) {
                ex.printStackTrace();
            }
       }

       }
private void Delp() throws IOException
{  StreamConnection con= null;
   StreamConnectionNotifier service= null;
   InputStream ip= null;
   OutputStream op=null;
   String serviceURL="btspp://localhost:1101;name=Program";
    service=(StreamConnectionNotifier)Connector.open(serviceURL);
    con=service.acceptAndOpen();
    ip=con.openInputStream();
    op=con.openOutputStream();
      ReadThread rdthr=new ReadThread(ip,op);
      rdthr.start();
}
}
class ReadThread extends Thread
{InputStream ip=null;OutputStream op=null;
 public ReadThread (InputStream inp,OutputStream onp){ip=inp;op=onp;}
 public void run()
 {
  try{char data;
      data=(char)ip.read();
      op.write(data);
     }
  catch(IOException e){}
 }
}

I just need to say that MY PROBLEM IS not knowing how to include the SPP connections into my code so that the connection would be accepted by java compiler...That's what I need help about...

Thanks in advance

I would be interested to know where you did get that URL for bluetooth from?
As the error message protocol doesn't exists as you provided malformed URL. Read this on how URL should be correctly formatted and if you wish to connect to a device either find his ID or use discovery to find any bluetooth devices in proximity. Here is limited preview of chapter Bluetooth and Obex from Beginning J2ME - From Novice to Professional that will get you started

The book from which I took a code ressembles my code is "Bluetooth and java" look at p123 to see the ChatServer code where he didnot use any initialization for his code.Why didnot he initialize his code?
In addition I cannot find the class com.atinav.bcc or even com.rococosoft although I searched on the internet...

That books Bluetooth for Java is too old and uses old packages that are not available any more. Get something newer. Either Beginning J2ME as I suggested in my previous post or the latest copy of Kicking butt with MIDP and MSA

There is no single old import among the present imports they are all present in many codes used in your book and the way of writing codes by defining StreamConnection and StreamConnectionNotifier is used everywhere on the internet...If you mean Rocococoft and atinav I found posts which might be useful to you too that I donot need a third party classes to run this on mobile so the problem now is in the btspp again

The link is from Nokia Forum:
http://discussion.forum.nokia.com/forum/showthread.php?p=689118
And by the by they are using the same book u refuse and this was @2009 i.e. only one year ago

There is no single old import among the present imports they are all present in many codes used in your book and the way of writing codes by defining StreamConnection and StreamConnectionNotifier is used everywhere on the internet...If you mean Rocococoft and atinav I found posts which might be useful to you too that I donot need a third party classes to run this on mobile so the problem now is in the btspp again

What I was saying is not that you have some "old imports" but that you are trying to "import old packages" that are not used any more. And as I said before your connection string "btspp" is wrong because you either have to know device id or you have to first search for available devices and get their ids so you can build your connection string

The link is from Nokia Forum:
http://discussion.forum.nokia.com/forum/showthread.php?p=689118
And by the by they are using the same book u refuse and this was @2009 i.e. only one year ago

If you have read whole tread carefully you would have found that they think, same as me, that code is old and crap

You are right about that code...now I have 2 questions:
1-Iam writing a server code not a client code so Should I search for devices or this applies to client too?
2-What do you mean by device ID I don't think that you mean UUID as it is reserved for a certain service isn't it? explain the ID you mean please

I would like to ask for a correct implementation for UUID.class as I may solve the problem through identifying the uuid itself as:

UUID serviceUUID = new UUID(0x1101L);
   String serviceURL = "btspp://localhost:" + serviceUUID.toString() + ";name=com.example";

The problem is that the javac tells me that this is a bad class... so can anyone provide me a UUID.java or UUID.class or tell me where can I find it
Thanks

Sorry forget about the wrong class just look at the 2 questions:
You are right about that code...now I have 2 questions:
1-Iam writing a server code not a client code so Should I search for devices or this applies to client too?
2-What do you mean by device ID I don't think that you mean UUID as it is reserved for a certain service isn't it? or you mean Browse Group UUID???

1-Iam writing a server code not a client code so Should I search for devices or this applies to client too?

Servers as always plays passive role. Server is set as discoverable and it is client that active player searching for service.

2-What do you mean by device ID I don't think that you mean UUID as it is reserved for a certain service isn't it? or you mean Browse Group UUID???

Yes, I meant UUID that is mobile "MAC" address of devices.

I think that UUID I mean is service dependent not mobile dependent such that for example RFCOMM have X0003 and SPP have X1101...Refer to book Bluetooth Essentials for Programmers Page 20.
waiting for reply

Sorry here is correction

A UUID is a Universally Unique identifier. This is usually a very large number, typically 128 bits. UUIDs are generated using combination of unique items (such as the MAC address on an ethernet interface) and random elements (the clock ticks on the computer at time of number generation). The idea is that the probability of two numbers generated, anywhere in the world, at any time, is infinitesimally small.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.