Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
rizinbox
Posts: 134
Registered: 10-24-2010
My Carrier: du

BlueTooth : Uncaught exception: no application instance

I am trying to search Bluetooth listening :

 

Here is my code 

 

 

public class BlueToothListener implements DiscoveryListener {

	BlueToothListener()
	    {
	    }
	    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
	    {
	        try
	        {
	            Dialog.alert("Device discovered " + btDevice.getFriendlyName(true));
	        }
	        catch(Exception e)
	        {
	        	Dialog.alert("device discovered errory");
	        }
	    }
	    
	    public void inquiryCompleted(int discoveryType)
	    {
	        Dialog.alert("Inquiry Completed");
	    }
	    
	    public void servicesDiscovered(int tranID, ServiceRecord[] serviceRecord)
	    {
	        Dialog.alert("Services Discovered");
	    }
	    
	    public void serviceSearchCompleted(int tranID, int respCode)
	    {
	        Dialog.alert("Service Search Completed");
	    }
	    public static void main(String ar[])
	    {
	    	 try
	         {
	            LocalDevice localDevice = LocalDevice.getLocalDevice();
	                
	            DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent();
	            BlueToothListener btlistener = new BlueToothListener();     
	           
	            discoveryAgent.startInquiry(DiscoveryAgent.GIAC, btlistener);
	         }
	         catch(Exception e)
	         {
	             
	             Dialog.alert("Exception Bluetooth : "+e.getMessage());
	         }
	    	
	    }

 

 

when I run this I receive exception "Uncaught exception: no application instance"

 

Tell me if anyone have idea... 

 

I am testing it on Blackberry 8520 curve and BlackBerry Bold.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

--
please mark posts as solved if you found a solution.
press the like button on the right side to thank the user that helped you.
------------------------------------------------------------
Riz
Please use plain text.
Developer
rizinbox
Posts: 134
Registered: 10-24-2010
My Carrier: du

Re: BlueTooth : Uncaught exception: no application instance

anyone?

--
please mark posts as solved if you found a solution.
press the like button on the right side to thank the user that helped you.
------------------------------------------------------------
Riz
Please use plain text.
Developer
RexDoug
Posts: 4,649
Registered: 07-21-2008

Re: BlueTooth : Uncaught exception: no application instance

This error means that your application has never entered the event dispatcher.

 

See Application or UiApplication classes in the javadocs. You need an instance of one of these classes, and this instance must enter the event dispatcher.

 

 

 

Please use plain text.
Developer
rizinbox
Posts: 134
Registered: 10-24-2010
My Carrier: du

Re: BlueTooth : Uncaught exception: no application instance

thanks for your reply I solve that error. Allhumdulillah

 

But know problem is I have 3 4 devices with in range but deviceDiscoverd only 1.

 

 

discovery_agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
discovery_agent.startInquiry(DiscoveryAgent.GIAC, this);

 

 

 

 

public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) 
	{
		try
		{
		
		if(cod.getMajorDeviceClass() == 0x0100 || cod.getMajorDeviceClass() == 0x0200)
		{
			remote_device.addElement(btDevice);
		}
		add(new LabelField(btDevice.getFriendlyName(true)));
		}catch(Exception ex)
		{
			Dialog.alert(ex.getMessage());
		}
	}

	public void inquiryCompleted(int discType)
	{
		switch(discType)
		{
			case DiscoveryListener.INQUIRY_COMPLETED:
				System.out.println("Device Search Completed");
				add(new LabelField(remote_device.size()+"  "+device_found.size()));
				
				break;
				
			case DiscoveryListener.INQUIRY_ERROR:
				System.out.println("Device Search Error");
				Dialog.alert("Device Search Error");
				break;				
			case DiscoveryListener.INQUIRY_TERMINATED:
				System.out.println("Device Search Terminated");
				Dialog.alert("Device Search Terminated");
				break;
		}
		
		try
		{			
			for(int i=0, cnt=remote_device.size(); i<cnt; i++)
			{
				discovery_agent.searchServices(new int[]{ 0x0100, 0x0200 }, new UUID[]{ new UUID(0x0003), new UUID(CHATTANDO_UUID, false) }, (RemoteDevice) remote_device.elementAt(i), this);
				waitForSearchDone();
			}
		}
		catch(Exception error)
		{
			error.printStackTrace();
		}
	}

	// Aspetta che la ricerca dei servizi per il dispositivo sia terminata
	private void waitForSearchDone()
	{
		searchDone = false;
		
		try
		{
			while(!searchDone)
			{
				synchronized(this)
				{
					this.wait();
				}
			}
		}
		catch(Exception error)
		{
			Dialog.alert(error.getMessage());
		}
	}
	
	public void serviceSearchCompleted(int transID, int respCode)
	{
		switch(respCode)
		{
			case DiscoveryListener.SERVICE_SEARCH_COMPLETED:
				System.out.println("Service Search Completed");
				break;
			case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
				System.out.println("Service Search Device not Reachable");
				break;
			case DiscoveryListener.SERVICE_SEARCH_ERROR:
				System.out.println("Service Search Error");
				break;
			case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:
				System.out.println("Service Search No Records");
				break;
			case DiscoveryListener.SERVICE_SEARCH_TERMINATED:
				System.out.println("Service Search Terminated");
				break;
		}
		
		searchDone = true;
		
		
		synchronized(this)
		{
			this.notifyAll();
		}
	}

	public void servicesDiscovered(int transID, ServiceRecord[] servRecord)
	{
		for(int i=0, cnt=servRecord.length; i<cnt; i++)
		{
			if(((String) servRecord[i].getAttributeValue(0x0100).getValue()).equalsIgnoreCase(CHATTANDO_SERVICE))
			{
				device_found.addElement(servRecord[i].getHostDevice());
			}
		}
	}

 

 

I don't know why its show only one device..but almost time every time show other device 

 

 

 

 

 

 

 

--
please mark posts as solved if you found a solution.
press the like button on the right side to thank the user that helped you.
------------------------------------------------------------
Riz
Please use plain text.