我正在使用谷歌地图。当我第一次运行我的应用程序时,它显示错误。我点击强制关闭和应用程序再次运行,第二次一切都很好。这是我的日志猫:
08-17 07:06:35.288: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)
08-17 07:06:35.288: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)
08-17 07:06:35.288: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)
08-17 07:06:35.288: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)
08-17 07:06:43.888: ERROR/BatteryService(51): usbOnlinePath not found
08-17 07:06:43.888: ERROR/BatteryService(51): batteryVoltagePath not found
08-17 07:06:43.888: ERROR/BatteryService(51): batteryTemperaturePath not found
08-17 07:06:43.908: ERROR/SurfaceFlinger(51): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
08-17 07:06:47.309: ERROR/EventHub(51): could not get driver version for /dev/input/mouse0, Not a typewriter
08-17 07:06:47.309: ERROR/EventHub(51): could not get driver version for /dev/input/mice, Not a typewriter
08-17 07:06:47.539: ERROR/System(51): Failure starting core service
08-17 07:06:47.539: ERROR/System(51): java.lang.SecurityException
08-17 07:06:47.539: ERROR/System(51): at android.os.BinderProxy.transact(Native Method)
08-17 07:06:47.539: ERROR/System(51): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
08-17 07:06:47.539: ERROR/System(51): at android.os.ServiceManager.addService(ServiceManager.java:72)
08-17 07:06:47.539: ERROR/System(51): at com.android.server.ServerThread.run(SystemServer.java:176)
08-17 07:06:47.548: ERROR/AndroidRuntime(51): Crash logging skipped, no checkin service
08-17 07:06:52.005: ERROR/ActivityThread(93): Failed to find provider info for android.server.checkin
08-17 07:06:52.905: ERROR/ActivityThread(93): Failed to find provider info for android.server.checkin
08-17 07:06:52.974: ERROR/ActivityThread(93): Failed to find provider info for android.server.checkin
08-17 07:06:54.728: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound)
08-17 07:06:54.934: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound
08-17 07:06:54.944: ERROR/MediaPlayer(51): Unable to to create media player
08-17 07:06:57.375: ERROR/ActivityThread(51): Failed to find provider info for com.google.settings
08-17 07:06:57.375: ERROR/ActivityThread(51): Failed to find provider info for com.google.settings
08-17 07:07:00.225: ERROR/AndroidRuntime(207): ERROR: thread attach failed
08-17 07:07:01.955: ERROR/AndroidRuntime(220): ERROR: thread attach failed
08-17 07:07:07.805: ERROR/ActivityThread(233): Failed to find provider info for com.google.settings
08-17 07:07:07.805: ERROR/ActivityThread(233): Failed to find provider info for com.google.settings
08-17 07:07:07.885: ERROR/ActivityThread(233): Failed to find provider info for com.google.settings
08-17 07:07:08.265: ERROR/AndroidRuntime(233): Uncaught handler: thread main exiting due to uncaught exception
08-17 07:07:08.275: ERROR/AndroidRuntime(233): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.projekat/test.projekat.TrenutnaLokacija}: java.lang.NullPointerException
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.os.Looper.loop(Looper.java:123)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at java.lang.reflect.Method.invoke(Method.java:521)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at dalvik.system.NativeStart.main(Native Method)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): Caused by: java.lang.NullPointerException
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at test.projekat.TrenutnaLokacija.onCreate(TrenutnaLokacija.java:91)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
08-17 07:07:08.275: ERROR/AndroidRuntime(233): ... 11 more
我的问题是:
08-17 07:07:08.275: ERROR/AndroidRuntime(233): Caused by: java.lang.NullPointerException
08-17 07:07:08.275: ERROR/AndroidRuntime(233): at test.projekat.TrenutnaLokacija.onCreate(TrenutnaLokacija.java:90)
firstDot = new GeoPoint((int) (location.getLatitude()*1E6),(int) (location.getLongitude()*1E6));
我编辑了问题...这是我的代码...位置为空..我在Android手机上启动了我的应用程序,但它不起作用...
public void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.pocetna);
mapView = (MapView) findViewById(R.id.mapview);
textView = (TextView) findViewById(R.id.text1);
textView3 = (TextView) findViewById(R.id.textView2);
mapController = mapView.getController();
mapController.setZoom(17);
mapView.setStreetView(true);
mapView.setBuiltInZoomControls(true);
button = (Button) findViewById(R.id.button1);
//mapView.setSatellite(true);
sb = (SeekBar) findViewById(R.id.seekBar1);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
updateWithNewLocation(null);
}
@Override
public void onLocationChanged(Location location) {
// TrenutnaLokacija.this.location = location;
updateWithNewLocation(location);
}
};
Criteria criteria = new Criteria();
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAccuracy(Criteria.ACCURACY_FINE);
provider = locationManager.getBestProvider(criteria, true);
locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
try{
location = locationManager.getLastKnownLocation(provider);
}catch (IllegalArgumentException e) {
Log.d("location", "Greska", e);
}catch (SecurityException s) {
Log.d("dsds", "Greska", s);
}
AlertDialog ad1 = new AlertDialog.Builder(this).create();
ad1.setTitle("Greska");
ad1.setMessage("Trenutno nisu ucitane lokacije");
ad1.setButton(DialogInterface.BUTTON_POSITIVE, "Dozvoli", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface ad, int which) {
}
});
if(location == null){
ad1.show();
Intent i = new Intent(TrenutnaLokacija.this, PronadjiKlopuActivity.class);
startActivity(i);
}
GeoPoint firstDot = new GeoPoint((int) (location.getLatitude()*1E6),(int) (location.getLongitude()*1E6));
myPosition = new NewItemizedOverlay(getResources().getDrawable(R.drawable.map_pin), firstDot);
listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(myPosition);
答案 0 :(得分:0)
第91行的TrenutnaLokacija课程中有空指针异常
这通常是在您尚未实例化变量的情况下,或者您正在从sharedpreferences或其他类调用中检索,如果找不到您指定的内容,则返回null。
http://www.javacoffeebreak.com/articles/toptenerrors.html请参阅第1号!
编辑
因为你说它第二次运行正常,听起来你想要获得一个位置,但它还没有加载到你的onCreate()
这里可能的位置为空:
location.getLatitude();