Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Code Problem

Options
  • 13-03-2006 3:46pm
    #1
    Registered Users Posts: 9,225 ✭✭✭


    import java.io.*;
    import javax.bluetooth.*;

    public class btTest {

    public static void main(String[] args) {
    String connectionURL="btspp://123456123456:1;encrypt=false;authenticate=false;master=true";

    Connection con=Connector.open(connectionURL);
    Runnable r=new Runnable() {
    public void run() {
    byte b[] = new byte[200];
    try {
    while (running) {
    dataReceived.setText("Received " + received);
    int a = is.read(b);
    received += a;
    }
    } catch (Exception e) {e.printStackTrace();running=false; }
    }
    } // getting error "Syntax error, insert ";" to complete LocalVariableDeclarationStatement" here

    //Starts the thread used to read data
    new Thread(r).run();

    //Write some data
    ((StreamConnection)streamCon).openDataOutputStream().writeChars("Try to write");

    }
    }

    ok this code is horribly wrong but how? i cant seem to fix it, any help would be great thanks, btw I am using Avetana but it is more likely a problem with my thread implementation than bluetooth.

    thanks!


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    What is "streamCon". Its not declared anywhere.


  • Registered Users Posts: 29 steve04


    Think you missing a semi-colon there after the new runnable declaration

    e.g.
    Runnable r=new Runnable() 
    		{...};
    


  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    steve04 wrote:
    Think you missing a semi-colon there after the new runnable declaration

    e.g.
    Runnable r=new Runnable() 
    		{...};
    

    but then i get
    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    	Connection cannot be resolved to a type
    	Connector cannot be resolved
    	running cannot be resolved
    	dataReceived cannot be resolved
    	received cannot be resolved
    	is cannot be resolved
    	received cannot be resolved
    	running cannot be resolved
    	StreamConnection cannot be resolved to a type
    	streamCon cannot be resolved
    
    	at btTest.main(btTest.java:9)
    


  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    Hobbes wrote:
    What is "streamCon". Its not declared anywhere.

    i took this code from the avetana website, i dont really know what its doing...


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Call_me_al wrote:
    but then i get
    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    	Connection cannot be resolved to a type
    	Connector cannot be resolved
    	running cannot be resolved
    	dataReceived cannot be resolved
    	received cannot be resolved
    	is cannot be resolved
    	received cannot be resolved
    	running cannot be resolved
    	StreamConnection cannot be resolved to a type
    	streamCon cannot be resolved
    
    	at btTest.main(btTest.java:9)
    

    some of those would be in the bluetooth kit. The thing looks like a code snippet rather then working code.


  • Advertisement
  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Call_me_al wrote:
    i took this code from the avetana website, i dont really know what its doing...

    It looks like it sets up a bluetooth connection for people to connect to, then tries to make a connection and send in text. That in turn is put into a variable which is never declared as well.

    Too much missing for it to do anything of note.


  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    well has anyone written anything like this before, or has a link to code using Avetana. i am fecking stuck.


  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    ok i put this together and i am getting some results but i have a few questions...
    import java.io.*;
    
    import javax.bluetooth.*;
    import javax.microedition.io.Connection;
    import javax.microedition.io.StreamConnection;
    
    import de.avetana.bluetooth.connection.Connector;
    import javax.microedition.io.OutputConnection;
    	
    public class btTest {
    
    	public static void main(String[] args) throws IOException {
    		String connectionURL="btspp://000A840029D9:1;authenticate=false;master=false;encrypt=false";
    		
    		StreamConnection connection =
    		    (StreamConnection) Connector.open(connectionURL);
    		boolean conn = true;
    		while(conn){
    			try {
    				byte buffer[] = new byte[100];
    				InputStream is = connection.openInputStream();
    				// send data to the server
    				// read data from the server
    				is.read(buffer);
    				System.out.println(buffer);
    				connection.close();
    			} catch(IOException e) {
    				e.printStackTrace();
    				conn=false;
    			}
    		}
    	}
    }
    

    i am getting this error when i run the code (it compiles fine) :
    2006-03-14 15:50:08.147 java[234] *** _NSAutoreleaseNoPool(): Object 0x318660 of class NSCFString autoreleased with no pool in place - just leaking
    

    and these are just some of the results i get when i print out the buffer:
    [B@92b996
    [B@8aaa1e
    [B@a6aeed
    [B@26804e
    
    or
    
    [B@92b996
    [B@193779
    [B@8916a2
    [B@2ce908
    [B@77158a
    [B@27391d
    [B@16ab4e
    [B@48aa23
    [B@99f91c
    [B@b1aa65
    [B@29f3b5
    [B@3f3045
    [B@7a29a1
    


    does anyone know what 1. how i convert the output to a string or 2. what the error means and finally how can i fix the error?

    once again thanks and any input is bery much appreciated!!

    OH! and its connecting to a GPS device


Advertisement