获取自己位置的移动设备的位置

时间:2012-04-23 11:43:01

标签: android gps latitude-longitude

我正在尝试获取自己的位置.Below是给我一些错误的代码。 Log Cat在下面给出..请帮忙 并且还想知道存储纬度和经度的变量。

MyLocation.java

public class MyLocation extends Activity{ 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.main); 

  /* Use the LocationManager class to obtain GPS locations */ 
  LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

  LocationListener mlocListener = new MyLocationListener(); 
  mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 
} 

/* Class My Location Listener */ 
public class MyLocationListener implements LocationListener 
{ 

  public void onLocationChanged(Location loc) 
  { 

    loc.getLatitude(); 
    loc.getLongitude(); 

    String Text = "My current location is: " + 
    "Latitud = " + loc.getLatitude() + 
    "Longitud = " + loc.getLongitude(); 

    Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show(); 
  } 

  public void onProviderDisabled(String provider) 
  { 
    Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show(); 
  } 

  public void onProviderEnabled(String provider) 
  { 
    Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show(); 
  } 

  public void onStatusChanged(String provider, int status, Bundle extras) 
  { 

  } 
} 
} 

Log Cat

04-23 16:41:27.880: E/AndroidRuntime(3250): Uncaught handler: thread main exiting due to uncaught exception
04-23 16:41:27.920: E/AndroidRuntime(3250): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{your.meh.namespace/your.meh.namespace.PostActivity}: java.lang.ClassNotFoundException: your.meh.namespace.PostActivity in loader dalvik.system.PathClassLoader@458a8ad8
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2424)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.app.ActivityThread.access$2200(ActivityThread.java:123)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.os.Looper.loop(Looper.java:123)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.app.ActivityThread.main(ActivityThread.java:4370)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at java.lang.reflect.Method.invokeNative(Native Method)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at java.lang.reflect.Method.invoke(Method.java:521)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at dalvik.system.NativeStart.main(Native Method)
04-23 16:41:27.920: E/AndroidRuntime(3250): Caused by: java.lang.ClassNotFoundException: your.meh.namespace.PostActivity in loader dalvik.system.PathClassLoader@458a8ad8
04-23 16:41:27.920: E/AndroidRuntime(3250):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-23 16:41:27.920: E/AndroidRuntime(3250):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
04-23 16:41:27.920: E/AndroidRuntime(3250):     ... 11 more
04-23 16:41:28.010: E/SemcCheckin(3250): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump
04-23 16:41:28.040: I/dalvikvm(3250): threadid=7: reacting to signal 3
04-23 16:41:28.100: I/dalvikvm(3250): Wrote stack trace to '/data/anr/traces.txt'

1 个答案:

答案 0 :(得分:1)

您的错误(根据您粘贴的堆栈跟踪)与位置问题无关。

找不到导致ClassNotFoundException的类PostActivity。

我认为你还没有粘贴实际失败的代码