Thanks Iyer! On Oct 15, 8:04 am, Prakash Iyer <thei...@gmail.com> wrote: > Your catching a NullPointerException in your > inputConnection.getTextBeforeCursor call is unnecessary. You are already > checking to see if inputConnection is null. It From the documentation of > InputConnection, and I quote > > This method may fail either if the input connection has become invalid (such > as its process crashing) or the client is taking too long to respond with > the text (it is given a couple seconds to return). In either case, a null is > returned. > > end quote. So I would guess your NullPointerException is possibly in the > fact that the cSeq is null and you are calling the method length() on a > possibly null object. > > In the future you will be better off reading and sending logcat output which > would probably have told you the line no where the Exception was thrown and > hence made it simpler... > > On Fri, Oct 15, 2010 at 10:53 AM, Saied <saie...@gmail.com> wrote: > > Hello, > > > This is baffling me. It must be something that I am doing wrong > > fundamentally, but for the life of me I can't see it > > Can a good soul help me please? > > > I am (supposedly) catching NullPointerException and returning 0 if > > that happens. But occasionally I get > > NullPointerException failure anyway. > > > Is catching it this way no enough to prevent this failure? > > > Thanks for your help. > > > private char getCharBehindCursor (int offset){ // get a single char > > behind cursor + offsett > > CharSequence cSeq; > > InputConnection inputConnection = getCurrentInputConnection(); > > if (inputConnection != null){ > > try { > > cSeq = inputConnection.getTextBeforeCursor > > (offset + 1, 0); > > } catch (NullPointerException npe) { > > /* failure*/ > > return (char)0; > > } > > > if (cSeq.length() == offset+1){ > > return cSeq.charAt(0); > > } > > } > > return (char)0; > > } > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > >
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en