현재 인텐트에서 지도 버튼을 누르면
현재 인텐트에 받아놓은 버스정류장의 위도, 경도 좌표를 지도 인텐트로 넘겨 구글맵을 연동시키고 그 위치에
마커를 찍고자 합니다. 자꾸 앱을 키면 실행이 되다 중간에 중단이 되는데 도저히 제가 뭘 잘못했는지 모르겠어서 질문 올립니다.....
----구글맵 연동할 클래스 입니다-----
import android.*;
public class MapLocation extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap gMap;
Intent intent = this.getIntent();
double currLatitude=intent.getDoubleExtra("lat",-1);
double currLongitude=intent.getDoubleExtra("lon",-1);
String string="";
LatLng place;
@Override
protected void onCreate(Bundle savedInstanceState) {
place = new LatLng(currLatitude, currLongitude);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
gMap = googleMap;
gMap.getUiSettings().setZoomControlsEnabled(true);
gMap.getUiSettings().setCompassEnabled(true);
gMap.getUiSettings().setMapToolbarEnabled(true);
// // LatLng : 위도 경도 잡아주는 객체
// // LatLng place = new LatLng(currLatitude, currLongitude);
//
// // 쥐잉~ 하면서 카메라 줌
// // 20 : 확대하는 정도
CameraPosition cameraPosition = new CameraPosition.Builder().target(place).zoom(15).build();
//
gMap.animateCamera(CameraUpdateFactory.newCameraPosition((cameraPosition)));
//
// // 좌표에 Marker가 꽂히게
gMap.addMarker(new MarkerOptions().position(place).title("검색한 정류소"));
gMap.addMarker(new MarkerOptions().position(place).snippet(string));
Toast.makeText(this, "lat: " + currLatitude + ", lon: " + currLongitude, Toast.LENGTH_SHORT).show();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
gMap.setMyLocationEnabled(true);
}
}
------현재 인텐트의 클래스입니다------
//버스 위치 지도버튼 눌렀을때
busBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// do something when the button is clicked
double d1=Double.valueOf(currentStation.getGpsX()).doubleValue();
double d2=Double.valueOf(currentStation.getGpsY()).doubleValue();
// Toast.makeText(getApplicationContext(), "d1="+ map.currLatitude, Toast.LENGTH_SHORT).show();
//map=new MapLocation(d1,d2,currentStation.getStNm());
//map.MoveMapLocation(d1,d2);
Intent intent1 = new Intent(StationActivity.this, MapLocation.class);
intent1.putExtra("lat", d1);
intent1.putExtra("lon", d2);
// intent1.putExtra("title", currentStation.getStNm());
startActivity(intent1);
// Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:"+d1+","+d2));
// intent1.setPackage("com.google.android.apps.maps");
// startActivity(intent1);
}
});
정류장의 좌표를 받아오는것은 문제가 전혀없습니다
문제는 인텐트로 넘겨줄때 발생하는 것입니다....
그치만 그 원인을 아무리 봐도 모르겠습니다 ㅜㅜㅜ 제발 알려주실수있을까요
----------------오류 로그입니다--------------
09-04 10:39:33.087 5206-5206/com.example.sy.bus_alime E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sy.bus_alime, PID: 5206
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.sy.bus_alime/com.example.sy.bus_alime.MapLocation}: java.lang.NullPointerException: Attempt to invoke virtual method 'double android.content.Intent.getDoubleExtra(java.lang.String, double)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double android.content.Intent.getDoubleExtra(java.lang.String, double)' on a null object reference