Looking at your code there is something strange that I'm almost
certain is the source of your NPE.

public RegistersActivity mDisplay = new RegistersActivity();

Why are you creating a new activity object? That's not going to be a
reference to the activity object that's visible and hence
any fields that you think are initialized in your activity or either
initialized or null. This is unrelated, but why would you make such a
field public?? Instance fields should almost always be private.


A service shouldn't access to fields of your activity. The whole point
is for it to be able to do work in the background whether the activity
object is present or not. If you need to do background tasks that are
more intimately connected with the activity use an inner AsyncTask.


Jonathan







On Jan 18, 10:44 pm, Roger Podacter <[email protected]> wrote:
> OK so I successfully got my app working with a few real-time graphs.
> I do all of my graph updating in my one activity of my tabbed app.
> However I wanted to now move the updating of my graph data into a
> service such that the data can still be collected and populated while
> the app is in the background, i.e. not in focus.  But for the life of
> me I keep getting a null pointer exception error and i can't solve
> it.
> It is difficult to post all of the code in this post, so perhaps i
> can
> link it and just describe what i am attempting.
>
> the 2 activities in question are RegistersActivity, which does all
> the
> graph functions, and BatteryCalibratorService, which i want to only
> call on RegistersActivity and update the graph accordingly.
>
> with all the code placed in one activity, RegistersActivity, the
> graph
> populates correctly just fine.  but as soon as i move my handler and
> runnable to
> my service, and attempt to call on my activity function from the
> service, i get the NPE.  specifically the error happens at line 91
> mDisplay.populateGraph(); of this 
> service:http://github.com/R0gerP0dacter/BatteryCalibrator/blob/master/src/net...
>
> the error happens simultaneously when i call my populateGraph
> function
> from my service, it errors at line 290 mCurrentSeries.clear(); of the
> activity:http://github.com/R0gerP0dacter/BatteryCalibrator/blob/master/src/net...
>
> the errors are linked, i.e. one is caused by the other, but i just
> can't understand why.  with all code in one main activity, everything
> works just fine.  but as soon as i try to use a service to call on my
> activity function (mDisplay.populateGraph()), i get the null pointer
> exception error.
>
> Hope this isn't too much to ask.  and yes i am a very novice/
> beginner/moderate coder, so please forgive if this is a dumb
> question!  thanks.
> RP

-- 
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