The line reporting the NPE is implicitly unboxing the Boolean returned by
your Map's get method to retrieve a primitive boolean value. If get returns
null it would have the behavior you describe.

On Tue, Jun 22, 2010 at 4:23 PM, Indicator Veritatis <[email protected]>wrote:

> Hi, Mariano
>
> True, this is a Java question, not an Android question. SO it doesn't
> r-e-a-l-l-y belong here. But in the interest of speeding you on your
> way, I will make a couple observations I hope you will find helpful.
>
> 1) no, the NPE does not imply that isMarkAllReadPossibleCache is the
> null variable. Rather, it implies that in the course of trying to
> execute the get method of isMarkAllReadPossibleCache, the DVM
> encountered a null pointer.
>
> 2) the NPE occurred during the call to UpdateButtons(), which in turn
> took place during the call to the above get() method.
>
> 3) to tell in any more detail where it came from, I would need the
> rest of your stack trace, which you chose not to show. But now you
> have a better idea how to narrow this down by yourself, without
> exposing the code to us, I hope.
>
> On Jun 22, 2:59 am, Mariano Kamp <[email protected]> wrote:
> > Hey guys.
> >
> > This is not an Android issue per-se, but I am puzzled about a Java issue
> and
> > want to pick your brains.
> >
> > I recently got a couple of bug reports with a NPE that I don't understand
> > and can't reproduce myself. Here is an abbreviated representation of the
> > offending class. I tried to stay as close to the actual code as possible.
> >
> > public class EntryManager {
> >
> >   private static EntryManager instance;
> >   private Map<DBQuery, Boolean> isMarkAllReadPossibleCache;
> >
> >   private EntryManager(Context ctx) {
> >     ..
> >     isMarkAllReadPossibleCache = new HashMap<DBQuery, Boolean>();
> >     ..
> >   }
> >
> >   public static synchronized EntryManager getInstance(final Context
> context)
> > {
> >        if (instance == null)
> >            instance = new EntryManager(context.getApplicationContext());
> >        return instance;
> >    }
> >
> >    void fireModelUpdated(final String atomId) {
> >         ..
> >         isMarkAllReadPossibleCache.clear();
> >         ..
> >    }
> >
> >   public boolean isMarkAllReadPossible(final DBQuery dbq) {
> >         if (!isMarkAllReadPossibleCache.containsKey(dbq))
> >             isMarkAllReadPossibleCache.put(dbq,
> > databaseHelper.isMarkAllReadPossible(dbq));
> >
> >        return isMarkAllReadPossibleCache.get(dbq); <!-- NPE is raised
> here
> >     }
> >    ..
> >
> > }
> >
> > In the last line from above a NPE is thrown. So the instance variable
> > isMarkAllReadPossibleCache must be null, right? But I don't see where
> this
> > could happen. It's initialized in the constructor and never set to null
> > afterwards.
> >
> > For completeness here is a stack trace:
> >
> > java.lang.NullPointerException
> > at com.newsrob.EntryManager.isMarkAllReadPossible(EntryManager.java:1529)
> > at
> >
> com.newsrob.activities.AbstractNewsRobListActivity.shouldMarkAllReadButtonBeEnabled(AbstractNewsRobListActivity.java:327)
> > at
> >
> com.newsrob.activities.AbstractNewsRobListActivity.updateButtons(AbstractNewsRobListActivity.java:236)
> > at
> >
> com.newsrob.activities.AbstractNewsRobListActivity.access$2(AbstractNewsRobListActivity.java:215)
> > <-- removed the private access modifier meanwhile
> > at
> >
> com.newsrob.activities.AbstractNewsRobListActivity$13.run(AbstractNewsRobListActivity.java:626)
> > at android.os.Handler.handleCallback(Handler.java:587)
> > at android.os.Handler.dispatchMessage(Handler.java:92)
> > at android.os.Looper.loop(Looper.java:123)
> > at android.app.ActivityThread.main(ActivityThread.java:4203)
> > at java.lang.reflect.Method.invokeNative(Native Method)
> > at java.lang.reflect.Method.invoke(Method.java:521)
> > at
> >
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
> > at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
> > at dalvik.system.NativeStart.main(Native Method)
> >
> > Any ideas?
> >
> > Cheers,
> > Mariano
>
> --
> 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]<android-developers%[email protected]>
> 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 [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