我尝试使用 GPS 制作一个用于地理定位的 Android 应用程序,但是当我运行模拟器时,我收到此消息:appname HAS unfortunately stopped.
为什么会收到此消息?我的代码没有错误。
我的.java:
package com.android.geolocalisation3;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class Geo3MainActivity extends MapActivity implements LocationListener {
private MapView mapView;
private MapController mc;
private LocationManager lm;
private double latitude=122;
private double longitude=37;
private double altitude=0;
private float accuracy=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geo3_main);
mapView = (MapView) this.findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
mc.setZoom(17);
}
@Override
protected void onResume() {
super.onResume();
lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0,
this);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0,
this);
}
@Override
protected void onPause() {
super.onPause();
lm.removeUpdates(this);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
mapView.setSatellite(true);
return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
mapView.setSatellite(false);
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_geo3_main, menu);
return true;
}
@Override
public void onLocationChanged(Location location) {
//altitude = location.getAltitude();
///accuracy = location.getAccuracy();
String msg = String.format(
getResources().getString(R.string.new_location), latitude,
longitude, altitude, accuracy);
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
GeoPoint p = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
mc.animateTo(p);
mc.setCenter(p);
}
@Override
public void onProviderDisabled(String provider) {
String msg = String.format(
getResources().getString(R.string.provider_disabled), provider);
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
String msg = String.format(
getResources().getString(R.string.provider_enabled), provider);
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
String newStatus = "";
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
newStatus = "OUT_OF_SERVICE";
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
newStatus = "TEMPORARILY_UNAVAILABLE";
break;
case LocationProvider.AVAILABLE:
newStatus = "AVAILABLE";
break;
}
String msg = String.format(
getResources().getString(R.string.provider_disabled), provider,
newStatus);
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
}
我的日志错误:
07-28 00:00:01.054: E/StrictMode(621): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-28 00:00:01.054: E/StrictMode(621): java.lang.Throwable: Explicit termination method 'close' not called
07-28 00:00:01.054: E/StrictMode(621): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-28 00:00:01.054: E/StrictMode(621): at android.database.CursorWindow.<init>(CursorWindow.java:137)
07-28 00:00:01.054: E/StrictMode(621): at android.database.CursorWindow.<init>(CursorWindow.java:41)
07-28 00:00:01.054: E/StrictMode(621): at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:681)
07-28 00:00:01.054: E/StrictMode(621): at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:679)
07-28 00:00:01.054: E/StrictMode(621): at android.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)
07-28 00:00:01.054: E/StrictMode(621): at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:34)
07-28 00:00:01.054: E/StrictMode(621): at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:30)
07-28 00:00:01.054: E/StrictMode(621): at android.content.ContentProviderProxy.query(ContentProviderNative.java:369)
07-28 00:00:01.054: E/StrictMode(621): at android.content.ContentResolver.query(ContentResolver.java:370)
07-28 00:00:01.054: E/StrictMode(621): at android.content.CursorLoader.loadInBackground(CursorLoader.java:65
07-28 00:00:01.054: E/StrictMode(621): at android.content.CursorLoader.loadInBackground(CursorLoader.java:43)
07-28 00:00:01.054: E/StrictMode(621): at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:301)
07-28 00:00:01.054: E/StrictMode(621): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:68)
07-28 00:00:01.054: E/StrictMode(621): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:56)
07-28 00:00:01.054: E/StrictMode(621): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-28 00:00:01.054: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-28 00:00:01.054: E/StrictMode(621): at java.lang.Thread.run(Thread.java:856)
07-28 00:00:01.144: E/StrictMode(621): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-28 00:00:01.144: E/StrictMode(621): java.lang.Throwable: Explicit termination method 'close' not called
07-28 00:00:01.144: E/StrictMode(621): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-28 00:00:01.144: E/StrictMode(621): at android.content.ContentResolver$CursorWrapperInner.<init>(ContentResolver.java:1835)
07-28 00:00:01.144: E/StrictMode(621): at android.content.ContentResolver.query(ContentResolver.java:392)
07-28 00:00:01.144: E/StrictMode(621): at android.content.CursorLoader.loadInBackground(CursorLoader.java:65)
07-28 00:00:01.144: E/StrictMode(621): at android.content.CursorLoader.loadInBackground(CursorLoader.java:43)
07-28 00:00:01.144: E/StrictMode(621): at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:301)
07-28 00:00:01.144: E/StrictMode(621): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:68)
07-28 00:00:01.144: E/StrictMode(621): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:56)
07-28 00:00:01.144: E/StrictMode(621): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-28 00:00:01.144: E/StrictMode(621): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-28 00:00:01.144: E/StrictMode(621): at java.lang.Thread.run(Thread.java:856)
07-28 00:00:45.364: E/PowerManagerService(157): Excessive delay setting brightness: 144ms, mask=2
07-28 00:00:45.544: E/PowerManagerService(157): Excessive delay setting brightness: 139ms, mask=2
07-28 00:00:45.764: E/PowerManagerService(157): Excessive delay setting brightness: 211ms, mask=2
07-28 00:00:45.994: E/PowerManagerService(157): Excessive delay setting brightness: 224ms, mask=2
07-28 00:05:21.293: E/ThrottleService(157): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)