Unfortunately the crash reports don't show the device model. The NPE happens 
when the user clicks a row or one of the buttons in a row (since all three 
actions share the same code). 

I have imagined a possible cause for this issue. Looking into the sources 
(android/view/View.java) here is what the constructor does when it founds 
android:onClick in XML: an anonymous listener is created, and this listener 
will call the method on the Context returned by View.getContext(), but this 
context may be a different instance than the one currently holding the view. 
This is because Adapter.getView() gives a chance for reusing an already 
existing View, and the default strategy for CursorAdapter (as seen in the 
sources) is to reuse that simply if it's not null. So here is my scenario
  1.. Instance#1 of MyActivity is created, its listview is set up and shown. 
Instance#1 is set as the listener for the list_item view, as per 
android:onClick in my XML layout 
  2.. onPause is called on instance#1, which causes my method to set adapter's 
cursor to null 
  3.. the system decides that a new instance of MyActivity is needed, so 
instance#2 is created. A new cursor is also created and its contents are shown 
in the list view (via bindView()), but the list item views are recycled 
somehow, since they were kept in a cache. The old views still keep a reference 
to instance#1, so when the click event is triggered, instance#1.onClick() is 
fired and it founds a null cursor, thus throwing the NPE 
This explanation requires a little bit of imagination, but I think it's still 
realistic, even if all is to be demonstrated. I am writing a separated, minimal 
test case to dive into the Android classes with the debugger, but it's not 
simple. I use an activity with a list view as the only content view, and a 
list_item with an android:onClick property defined in XML. My goal is to see if 
a new instance of the activity can be created even when another one is already 
available. From the Android doc, this would be perfectly legitimate, but is not 
easy to trigger. The second step is to click the list item and compare the 
list_item's context with the current Activity. If they are different, we have 
caught it.

Does anybody have any suggestion or experience on this?

@Jason, as per the tap tempo, the algorithm to detect the BPM requires three 
taps at enough close intervals, and the resulting value must also be in the 
constraints. If you try to tap while you listen a song, it will do its job

@Blake, I can argue it from the stack trace. The NPE is throws at this line
int position = cursor.getPosition();
so the cursor is obviously null, and the only code that change the cursor (and 
the adapter) is onPause(), where I set adapter.changeCursor(null);

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to