[Noisebridge-discuss] Android - BluetoothChat sample problem fixage?

Taylor Alexander tlalexander at gmail.com
Thu Dec 20 04:32:40 UTC 2012


So, the crash is caused when trying to set the status of the app in the
Action Bar. For some reason, the code (from BluetoothChat.java)

*final ActionBar actionBar = getActionBar();*

in both setStatus functions gets a value of null from getActionBar(). (I
don't know how that function is supposed to work, but one would assume it
would work on a 4.2 device)

Then the following line:

*actionBar.setSubtitle(resId);*

throws your null pointer exception, because the actionBar variable is null.

You could throw an if() in there and make sure the value isn't null, but I
imagine there's a bigger issue. You can also just comment out those lines
temporarily (that is, comment out both instances of  actionBar.setSubtitle
) to move past the issue for now.


The bigger question is: what phones do you want to support? The methods
causing the crash have to do with the Action Bar, which is only present in
android 4.0+ (or maybe that was 3.0+) devices. If you want to ensure
compatibility with more phones, supporting android 2.2+ is recommended. In
that case, you can probably just use the old bluetooth chat example from
2.2 and it should work fine. The new one may have some nicer features
though (it kind of looks like it does), so alternatively you can comment
out the offending lines and then put some conditional code around anything
that requires a newer version of android (not sure why Google didn't do
that...).

Anyway, to reiterate, you can get the example to run by commenting out the
contents of the methods below. Eventually you'll want to figure out why
it's crashing. And side note: I also had to set the minimum API level in
the manifest to 11 to get it to stop complaining at me for having those
ActionBar methods in the first place.

 private final void setStatus(int resId) {

        final ActionBar actionBar = getActionBar();

        actionBar.setSubtitle(resId);

    }


    private final void setStatus(CharSequence subTitle) {

        final ActionBar actionBar = getActionBar();

        actionBar.setSubtitle(subTitle);

    }


On Wed, Dec 19, 2012 at 8:10 PM, Taylor Alexander <tlalexander at gmail.com>wrote:

> :)
>
>
> On Wed, Dec 19, 2012 at 8:07 PM, Anders Nelson <anders.k.nelson at gmail.com>wrote:
>
>> I want you to know that I *actually *jumped upward and did a little
>> dance.
>>
>> --
>> Anders Nelson
>>
>> +1 (517) 775-6129
>>
>> www.erogear.com
>>
>>
>>
>> On Wed, Dec 19, 2012 at 8:05 PM, Taylor Alexander <tlalexander at gmail.com>wrote:
>>
>>> It crashes on my unit too. Debugging now.
>>>
>>>
>>> On Wed, Dec 19, 2012 at 7:56 PM, Anders Nelson <
>>> anders.k.nelson at gmail.com> wrote:
>>>
>>>> Attached is a screenshot of the system specs. Thanks sooo much for your
>>>> help!
>>>>
>>>> =]
>>>>
>>>> --
>>>> Anders Nelson
>>>>
>>>> +1 (517) 775-6129
>>>>
>>>> www.erogear.com
>>>>
>>>>
>>>>
>>>> On Wed, Dec 19, 2012 at 7:53 PM, Taylor Alexander <
>>>> tlalexander at gmail.com> wrote:
>>>>
>>>>> Let me download the latest example code and try running it. I'm
>>>>> working from a copy of the bluetoothchat program from android 2.2 or so.
>>>>> They may have changed it recently and broken something.
>>>>>
>>>>> Which, by the way, you might want to try - go grab an older version
>>>>> and try running it. I think that's easy enough to do. I forget off the top
>>>>> of my head. I'll report back in a few.
>>>>>
>>>>>
>>>>> On Wed, Dec 19, 2012 at 7:49 PM, Anders Nelson <
>>>>> anders.k.nelson at gmail.com> wrote:
>>>>>
>>>>>> Hey Taylor,
>>>>>>
>>>>>> Thanks for the response! There may be something awkward with the fact
>>>>>> that my GNex is the international GSM version and it's not based on the
>>>>>> yakju system image. I'm not sure what it is but the phone has not been
>>>>>> particularly stable at times.
>>>>>>
>>>>>> My symptoms are that the app seems to crash immediately upon creation
>>>>>> of a thread (if I'm reading the debug messages correctly) and cites a null
>>>>>> reference exception or something. I don't even get to the part where the
>>>>>> program conects to another device, nor even draws the UI.
>>>>>>
>>>>>> Am I doing something stupid?
>>>>>>
>>>>>> --
>>>>>> Anders Nelson
>>>>>>
>>>>>> +1 (517) 775-6129
>>>>>>
>>>>>> www.erogear.com
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Dec 19, 2012 at 7:45 PM, Taylor Alexander <
>>>>>> tlalexander at gmail.com> wrote:
>>>>>>
>>>>>>> Here is the fix for the RN-42:
>>>>>>>
>>>>>>> Jonathon Cox <http://www.sparkfun.com/users/65> | about a year ago<https://www.sparkfun.com/products/10253#comment-4eaad857757b7fd35100af3e>
>>>>>>>   1 <http://www.sparkfun.com/static/comment_help>
>>>>>>>
>>>>>>> You can also use the BluetoothChat example in the Android SDK to
>>>>>>> connect to the module. Just change the UUID like this:
>>>>>>> private static final UUID MY_UUID =
>>>>>>> UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”);
>>>>>>>
>>>>>>> via https://www.sparkfun.com/products/10253
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Dec 19, 2012 at 7:41 PM, Taylor Alexander <
>>>>>>> tlalexander at gmail.com> wrote:
>>>>>>>
>>>>>>>> It works on my galaxy nexus. (4.2, was 4.1 and 4.0, all worked)
>>>>>>>>
>>>>>>>> I do know that this won't work with the popular RN-42 (and 41)
>>>>>>>> bluetooth to serial modules unless you change one line of code. Are you
>>>>>>>> using one of those? I can look up what the change is if need be. I also
>>>>>>>> posted it on stackoverflow at one point.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Dec 19, 2012 at 7:38 PM, Anders Nelson <
>>>>>>>> anders.k.nelson at gmail.com> wrote:
>>>>>>>>
>>>>>>>>> Helloooooooo you wonderful people!
>>>>>>>>>
>>>>>>>>> Does someone on this list have experience with getting the
>>>>>>>>> BluetoothChat Android SDK sample working? Can you help me get it to *not*
>>>>>>>>> crash upon launch?
>>>>>>>>>
>>>>>>>>> I'm building a Bluetooth-based program on the Android platform and
>>>>>>>>> I've managed to give myself a bald spot trying to figure out why a certain
>>>>>>>>> Android SDK sample is immediately crashing when I open it on my Galaxy
>>>>>>>>> Nexus phone. It's really important that I get this to simply run, the rest
>>>>>>>>> I can do myself!
>>>>>>>>>
>>>>>>>>> Here's why it's important - as some of you may know, I've spent
>>>>>>>>> the last year and six weeks completely redesigning my wearable LED display
>>>>>>>>> platform, and the beta articles are working beautifully as I feed them with
>>>>>>>>> video from my PC over Bluetooth. Buuuuut my main selling point is for
>>>>>>>>> mobile apps to feed these displays.
>>>>>>>>>
>>>>>>>>> Android ships their SDK with a great sample program containing a
>>>>>>>>> class that does the Bluetooth state/connection management for you on
>>>>>>>>> multiple threads for snappiness (and happiness). It's called
>>>>>>>>> "BluetoothChat". The problem I'm having is that it hasn't the facility to
>>>>>>>>> use Bluetooth in the emulator, and it also crashes upon launch when I debug
>>>>>>>>> using my Galaxy Nexus running ICS 4.1.1. I've Googled my tail off and went
>>>>>>>>> through many a tutorial already.
>>>>>>>>>
>>>>>>>>> Anyway, I live in SF but will travel. I will also pay/barter for
>>>>>>>>> your time.
>>>>>>>>>
>>>>>>>>> Cool?
>>>>>>>>>
>>>>>>>>> [image: Inline image 1]
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Anders Nelson
>>>>>>>>>
>>>>>>>>> +1 (517) 775-6129
>>>>>>>>>
>>>>>>>>> www.erogear.com
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Noisebridge-discuss mailing list
>>>>>>>>> Noisebridge-discuss at lists.noisebridge.net
>>>>>>>>> https://www.noisebridge.net/mailman/listinfo/noisebridge-discuss
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.noisebridge.net/pipermail/noisebridge-discuss/attachments/20121219/15376042/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.gif
Type: image/gif
Size: 9109 bytes
Desc: not available
URL: <http://lists.noisebridge.net/pipermail/noisebridge-discuss/attachments/20121219/15376042/attachment-0003.gif>


More information about the Noisebridge-discuss mailing list