Use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine
LogCat and look at the stack trace associated with your exception.

Also, I am not aware of any practical use for getBaseContext(). Just
call stopService() directly -- your Activity (the thing you are
calling getBaseContext() on) *is* a Context.

On Tue, Jun 7, 2011 at 10:24 AM, agrosner <agros...@fordham.edu> wrote:
> Hello, I use a button to stop a service from running in my
> application, but I got stuck when the application keeps crashing. Here
> is the code and line 8  is the problem code I found by using
> breakpoints, any suggestions?
>
> public void onClick(View v)
>        {
>                switch (v.getId())
>                {
>                        case R.id.exit_collection_button:
>                                this.finish();
>                                Context context = getBaseContext();
> 8                               context.stopService(new Intent(this, 
> CollectionService.class));//
> **********
>
>                                break;
>                }
>
>        }
> Stack trace:
> Thread [<3> main] (Suspended (exception RuntimeException))
>        ActivityThread.handleStopService(IBinder) line: 2909
>        ActivityThread.access$3600(ActivityThread, IBinder) line: 119
>        ActivityThread$H.handleMessage(Message) line: 1929
>        ActivityThread$H(Handler).dispatchMessage(Message) line: 99
>        Looper.loop() line: 123
>        ActivityThread.main(String[]) line: 4363
>        Method.invokeNative(Object, Object[], Class, Class[], Class, int,
> boolean) line: not available [native method]
>        Method.invoke(Object, Object...) line: 521
>        ZygoteInit$MethodAndArgsCaller.run() line: 860
>        ZygoteInit.main(String[]) line: 618
>        NativeStart.main(String[]) line: not available [native method]
>
> thanks
>
> --
> 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
>



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 3.4 Available!

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

Reply via email to