我正在做一個小應用程序,它需要當前的GPS值。爲此,我閱讀了許多教程,並嘗試使用此sample code。但我沒有得到價值。當我運行代碼強行關閉應用程序。這是我的logcat。沒有得到當前的GPS值
03-27 12:57:49.881: E/AndroidRuntime(604): FATAL EXCEPTION: main
03-27 12:57:49.881: E/AndroidRuntime(604): java.lang.UnsatisfiedLinkError: onCreate
03-27 12:57:49.881: E/AndroidRuntime(604): at com.google.android.maps.MapActivity.onCreate(Native Method)
03-27 12:57:49.881: E/AndroidRuntime(604): at com.android.and.AndActivity.onCreate(AndActivity.java:48)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.os.Looper.loop(Looper.java:123)
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-27 12:57:49.881: E/AndroidRuntime(604): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 12:57:49.881: E/AndroidRuntime(604): at java.lang.reflect.Method.invoke(Method.java:521)
03-27 12:57:49.881: E/AndroidRuntime(604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-27 12:57:49.881: E/AndroidRuntime(604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-27 12:57:49.881: E/AndroidRuntime(604): at dalvik.system.NativeStart.main(Native Method)
編輯
這裏是我的活動。
public class AndActivity extends Activity implements LocationListener {
private TextView latituteField;
private TextView longitudeField;
private LocationManager locationManager;
private String provider;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
latituteField = (TextView) findViewById(R.id.TextView02);
longitudeField = (TextView) findViewById(R.id.TextView04);
// Get the location manager
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
// Initialize the location fields
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
latituteField.setText(String.valueOf(lat));
longitudeField.setText(String.valueOf(lng));
} else {
latituteField.setText("Provider not available");
longitudeField.setText("Provider not available");
}
}
/* Request updates at startup */
@Override
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(provider, 400, 1, this);
}
/* Remove the locationlistener updates when Activity is paused */
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(this);
}
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
latituteField.setText(String.valueOf(lat));
longitudeField.setText(String.valueOf(lng));
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(this, "Disabled provider " + provider,
Toast.LENGTH_SHORT).show();
}
}
顯示您在此活動中使用的AndActivity'onCreate(..)'代碼和xml佈局。 – 2012-03-28 07:07:17
@ a.ch我在這裏添加了我的AndActivity .. – wolverine 2012-03-28 07:10:26
哪一行是您的活動中的第48位? – 2012-03-28 07:14:35