1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

Android application Crashes


Last Updated:

  1. Deewanagan

    Deewanagan New Member This Topic's Starter

    Joined:
    Jan 18, 2010
    Messages:
    4
    Likes Received:
    0
    hello everyone,

    I am very new to android programming. i was following a guide in here, to create an application that shows the current location, i did as was told in the guide, but whenever i try to run it, it crashes, and asks for "force Close",:(
    does somebody know what i am doing wrong? here is the code:
    Code (Text):
    1. package pro.googleLocation;
    2.  
    3. import android.app.Activity;
    4. import android.content.Context;
    5. import android.location.Location;
    6. import android.location.LocationListener;
    7. import android.location.LocationManager;
    8. import android.os.Bundle;
    9. import android.widget.TextView;
    10.  
    11. public class Finder extends Activity {
    12.     /** Called when the activity is first created. */
    13.     private LocationManager myLocationManager;
    14.     private LocationListener myLocationListener;
    15.     private TextView myLatitude, myLongitude;
    16.     @Override
    17.     public void onCreate(Bundle savedInstanceState) {
    18.         super.onCreate(savedInstanceState);
    19.         setContentView(R.layout.main);
    20.         myLatitude = (TextView)findViewById(R.id.Latitude);
    21.         myLongitude = (TextView)findViewById(R.id.Longitude);
    22.  
    23.         myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    24.         myLocationListener = new MyLocationListener();
    25.         myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,myLocationListener);
    26.         myLatitude.setText(String.valueOf(
    27.                   myLocationManager.getLastKnownLocation(
    28.                     LocationManager.GPS_PROVIDER).getLatitude()));
    29.  
    30.                 myLongitude.setText(String.valueOf(
    31.                  myLocationManager.getLastKnownLocation(
    32.                    LocationManager.GPS_PROVIDER).getLongitude()));
    33.     }
    34.     private class MyLocationListener implements LocationListener{
    35.  
    36.         public void onLocationChanged(Location argLocation) {
    37.         // TODO Auto-generated method stub
    38.         myLatitude.setText(String.valueOf(
    39.           argLocation.getLatitude()));
    40.         myLongitude.setText(String.valueOf(
    41.           argLocation.getLongitude()));
    42.         }
    43.  
    44.         public void onProviderDisabled(String provider) {
    45.         // TODO Auto-generated method stub
    46.         }
    47.  
    48.         public void onProviderEnabled(String provider) {
    49.         // TODO Auto-generated method stub
    50.         }
    51.  
    52.         public void onStatusChanged(String provider,
    53.          int status, Bundle extras) {
    54.         // TODO Auto-generated method stub
    55.         }
    56.         };
    57.        
    58. }
    log cat shows something like this:
    Code (Text):
    1. 01-18 22:12:46.017: WARN/dalvikvm(1091): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
    2. 01-18 22:12:46.017: ERROR/AndroidRuntime(1091): Uncaught handler: thread main exiting due to uncaught exception
    3. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091): java.lang.RuntimeException: Unable to start activity ComponentInfo{pro.googleLocation/pro.googleLocation.Finder}: java.lang.NullPointerException
    4. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
    5. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
    6. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
    7. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
    8. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.os.Handler.dispatchMessage(Handler.java:99)
    9. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.os.Looper.loop(Looper.java:123)
    10. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.app.ActivityThread.main(ActivityThread.java:4203)
    11. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at java.lang.reflect.Method.invokeNative(Native Method)
    12. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at java.lang.reflect.Method.invoke(Method.java:521)
    13. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    14. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
    15. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at dalvik.system.NativeStart.main(Native Method)
    16. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091): Caused by: java.lang.NullPointerException
    17. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at pro.googleLocation.Finder.onCreate(Finder.java:28)
    18. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
    19. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
    20. 01-18 22:12:46.037: ERROR/AndroidRuntime(1091):     ... 11 more
    21.  
     

    Advertisement
  2. Deewanagan

    Deewanagan New Member This Topic's Starter

    Joined:
    Jan 18, 2010
    Messages:
    4
    Likes Received:
    0
    found the problem. it crashed because the lat/longitude value wasn't being passed to the emulator.
     

Share This Page

Loading...