1

I have tried the sample code of Bluetooth chat from Android SDK. The code has no errors, Installed the APK on device, while opening the Bluetooth chat, Force close is thrown.

I used a real device to debug, i.e. Galaxy Nexus S.

Please help me . . Thanks in advance.

10101010
  • 607
  • 8
  • 24
  • @lokesh and anoop Okay .. the code is in the documentation itself named Bluetooth chat . I observed that if I remove the following line mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); , no exception is thrown . One more thing , i have android revision 15 and I am running it on jelly beans in galaxy nexus . Thanks for commenting guys . I am waiting for my answer . – 10101010 Nov 06 '12 at 16:52

2 Answers2

5

I managed to fix it by:

  1. Changing the AndroidManifest.xml: Basically upgrading the versions where it works <uses-sdk android:maxSdkVersion="17" android:targetSdkVersion="11" android:minSdkVersion="11"/> the 11th version is Android 3.0 (Honeycomb).
  2. Also deleted the line in the AndroidManifest.xml referring to the style android:theme="@android:style/Theme.Holo.Dialog"
  3. The main activity is BluetoothChat, so looking in the logCat I could see what else is throwing exceptions, the method setStatus around 233 is throwing a NullPointerEception due that the onCreate method needs the following code just bellow the super.onCreate call. Thanks to this post getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
Community
  • 1
  • 1
Eduardo
  • 133
  • 3
  • 8
0

I'm not sure if this still applies for you, but i encountered the same problem.

I downloaded the sample, loaded it on a Samsung S3(jellybean) and it kept crashing after the prompt for Bluetooth. There wasn't any error at first. So i tried using your method of removing mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter() in the code (on eclipse) and was prompted that it was read only and whether i want to make it writable. Upon doing that a few error came up and that was a prompt to say getDefaultAdapter is for API 5 and current minSdk is 1. Hence i looked up into the manifest file to see why it would be a problem since i put it as minSdkVersion=5.

Upon making the manifest file writable as previously mentioned for the java file, i realized the error was due to this line

android:theme="@android:style/Theme.Holo.Dialog"

it requires an API of 11. Hence i changed to android:minSdkVersion="11" and now it works perfectly.

HaemEternal
  • 2,229
  • 6
  • 31
  • 50
Winz
  • 1