“上的错误”;尝试调用虚拟方法';double java.lang.double.doubleValue()';“在空对象引用上”;
我刚刚遇到一个问题,就是通过从“上的错误”;尝试调用虚拟方法';double java.lang.double.doubleValue()';“在空对象引用上”;,java,android,google-maps,nullpointerexception,Java,Android,Google Maps,Nullpointerexception,我刚刚遇到一个问题,就是通过从SqliteDatabase访问纬度和经度来显示地图 当我运行此命令时,我在.target(新LatLng(纬度、经度))行上得到上述错误。任何帮助都将不胜感激 import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.Fragme
SqliteDatabase
访问纬度和经度来显示地图
当我运行此命令时,我在.target(新LatLng(纬度、经度))
行上得到上述错误。任何帮助都将不胜感激
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import static com.example.kod45.refapp.R.id.lat;
import static com.example.kod45.refapp.R.id.longitude;
public class Map extends FragmentActivity implements OnMapReadyCallback {
Double latitude;
Double longitude;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Tallaght and move the camera
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(latitude, longitude)) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Intent intent = getIntent();
intent.putExtra("latitude", latitude);
intent.putExtra("longitude", longitude);
// LatLng sydney = new LatLng(latitude, longitude);
}
}
您从未为其指定值
Double latitude;
Double longitude;
这就是你使用它们的地方
.target(new LatLng(latitude, longitude)) // Sets the center of the map to Mountain View
尝试为纬度和经度赋值-:
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import static com.example.kod45.refapp.R.id.lat;
import static com.example.kod45.refapp.R.id.longitude;
public class Map extends FragmentActivity implements OnMapReadyCallback {
Double latitude;
Double longitude;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
增加纬度和经度的价值,从哪里获得
“纬度”=
“长”=
getMapAsync(这个);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Tallaght and move the camera
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(latitude, longitude)) //here latitude and longtitude are null as no value is assigned to them // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Intent intent = getIntent();
intent.putExtra("latitude", latitude);
intent.putExtra("longitude", longitude);
// LatLng sydney = new LatLng(latitude, longitude);
}
}
您的纬度和经度为空,因为它们仅被声明,并且从未赋值 例如: 纬度=28.61391 经度=77.2068325
像这样设置位置,此位置位于德里,用于消除错误,地图活动显示,但它为空,不显示地图的任何特征