There are a couple of problems in your onResume() function.
1. It should call super.onResume()
2. Change
LocationManager manager = (null);
getSystemService(Context.LOCATION_SERVICE);
to
LocationManager manager = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
And make sure you request the following permission in your
AndroidManifest.xml file.
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"></uses-
permission>
--
Jack Ha
Open Source Development Center
・T・ ・ ・Mobile・ stick together
The views, opinions and statements in this email are those of
the author solely in their individual capacity, and do not
necessarily represent those of T-Mobile USA, Inc.
On May 21, 6:11 am, Gopal <[email protected]> wrote:
> I have try the code But i am facing from this exception:
> Firstly thanks for the code:
> And thanks in Advance:
>
> Please give me the correct direction where i am wrong please help me.
>
> My code is :
> .java
> package org.apache.sms;
> import android.app.Activity;
> import android.content.Context;
> import android.location.Location;
> import android.location.LocationListener;
> import android.location.LocationManager;
> import android.os.Bundle;
> import android.view.View;
> import android.widget.LinearLayout;
> import android.widget.TextView;
> import android.widget.LinearLayout.LayoutParams;
>
> public class SMSApp extends Activity {
> private TextView messageView;
>
> public class WhereamiLocationListener implements LocationListener {
>
> public void onLocationChanged(Location location) {
> if (location != null) {
> messageView.setText(location.toString());
> }
> }
>
> public void onProviderDisabled(String provider) {
> // TODO Auto-generated method stub
>
> }
>
> public void onProviderEnabled(String provider) {
> // TODO Auto-generated method stub
>
> }
>
> public void onStatusChanged(String provider, int status, Bundle
> extras) {
> // TODO Auto-generated method stub
>
> }
>
> }
> @Override
> public void onResume() {
> WhereamiLocationListener listener = new WhereamiLocationListener
> ();
> LocationManager manager = (null);
> getSystemService(Context.LOCATION_SERVICE);
>
> long updateTimeMsec = 1000L;
> manager.requestLocationUpdates
> (LocationManager.GPS_PROVIDER,
> updateTimeMsec, 500.0f,
> listener);
> manager.requestLocationUpdates
> (LocationManager.NETWORK_PROVIDER,
> updateTimeMsec, 500.0f,
> listener);
> }
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(makeContentView());
> }
>
> private View makeContentView() {
> LinearLayout panel = new LinearLayout(this);
> panel.setLayoutParams(new LayoutParams
> (LayoutParams.WRAP_CONTENT,
> LayoutParams.WRAP_CONTENT));
> panel.setOrientation(LinearLayout.VERTICAL);
> panel.addView(makeMessageView());
> return panel;
> }
>
> private View makeMessageView() {
> messageView = new TextView(this);
> messageView.setText("Loading...");
> return messageView;
> }
>
> private void updateWithNewLocation(Location location) {
> String latLongString;
> if (location != null) {
> double lat = location.getLatitude();
> double lng = location.getLongitude();
> latLongString = "Lat: " + lat + "\nLng: " + lng;
> } else {
> latLongString = "No Location Found";
> }
> messageView.setText("Your Current Location is:\n" +
> latLongString);
> }
> }
> --------------------------------------------
> *********************************-------------------------------
>
> .manifest file
> <?xml version="1.0" encoding="utf-8"?>
>
> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
>
> package="org.apache.sms"
>
> android:versionCode="1"
>
> android:versionName="1.0.0">
>
> <application android:icon="@drawable/icon" android:label="@string/
> app_name">
>
> <activity android:name=".SMSApp"
>
> android:label="@string/app_name">
>
> <intent-filter>
>
> <action android:name="android.intent.action.MAIN" />
>
> <category
> android:name="android.intent.category.LAUNCHER" />
>
> </intent-filter>
>
> </activity>
> <uses-permission android:name="android.permission.INTERNET"></uses-
> permission>
> <uses-permission
> android:name="android.permission.ACCESS_COARSE_LOCATION" />
>
> <uses-permission
> android:name="android.permission.ACCESS_FINE_LOCATION" />
>
> <uses-permission
> android:name="android.permission.ACCESS_LOCATION"
> />
>
> <uses-permission android:name="android.permission.ACCESS_GPS" /
>
>
>
> </application>
>
> </manifest>
>
> --------------------------------------
> ***************-----------------------------------------------------------
>
> Exception is:
> Shutting down VM
> 05-21 18:38:25.280: WARN/dalvikvm(723): threadid=3: thread exiting
> with uncaught exception (group=0x4000fe70)
> 05-21 18:38:25.290: ERROR/AndroidRuntime(723): Uncaught handler:
> thread main exiting due to uncaught exception
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723):
> java.lang.RuntimeException: Unable to resume activity {org.apache.sms/
> org.apache.sms.SMSApp}: java.lang.NullPointerException
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.ActivityThread.performResumeActivity(ActivityThread.java:
> 2632)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.ActivityThread.handleResumeActivity(ActivityThread.java:
> 2647)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
> 2287)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.ActivityThread.access$1800(ActivityThread.java:112)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.os.Handler.dispatchMessage(Handler.java:99)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.os.Looper.loop(Looper.java:123)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.ActivityThread.main(ActivityThread.java:3948)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> java.lang.reflect.Method.invokeNative(Native Method)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> java.lang.reflect.Method.invoke(Method.java:521)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
> (ZygoteInit.java:782)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> dalvik.system.NativeStart.main(Native Method)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): Caused by:
> java.lang.NullPointerException
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> org.apache.sms.SMSApp.onResume(SMSApp.java:48)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.Instrumentation.callActivityOnResume(Instrumentation.java:
> 1225)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.Activity.performResume(Activity.java:3530)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): at
> android.app.ActivityThread.performResumeActivity(ActivityThread.java:
> 2619)
> 05-21 18:38:25.341: ERROR/AndroidRuntime(723): ... 12 more
> 05-21 18:38:25.392: INFO/Process(570): Sending signal. PID: 723 SIG: 3
> 05-21 18:38:25.392: INFO/dalvikvm(723): threadid=7: reacting to signal
> 3
> 05-21 18:38:25.461: INFO/dalvikvm(723): Wrote stack trace to '/data/
> anr/traces.txt'
> 05-21 18:38:25.871: INFO/ARMAssembler(570): generated
> scanline__00000077:03515104_00000000_00000000 [ 27 ipp] (41 ins) at
> [0x2754f8:0x27559c] in 9999316 ns
> 05-21 18:38:33.834: WARN/ActivityManager(570): Launch timeout has
> expired, giving up wake lock!
> 05-21 18:38:34.907: WARN/ActivityManager(570): Activity idle timeout
> for HistoryRecord{43636d90 {org.apache.sms/org.apache.sms.SMSApp}}
> 05-21 18:38:40.090: DEBUG/dalvikvm(651): GC freed 2879 objects /
> 176856 bytes in 168ms
> 05-21 18:38:45.101: DEBUG/dalvikvm(611): GC freed 4190 objects /
> 235272 bytes in 178ms
> 05-21 18:38:50.191: DEBUG/dalvikvm(645): GC freed 1194 objects / 77416
> bytes in 241ms
> 05-21 18:38:55.141: DEBUG/dalvikvm(678): GC freed 2704 objects /
> 155800 bytes in 184ms
> 05-21 18:39:00.411: DEBUG/dalvikvm(614): GC freed 2362 objects /
> 126768 bytes in 445ms
>
> Thansk & Regards:
> Gopal Bisht
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---