1

새로운 프로젝트 "MapsActivity"를 만들었습니다. Google에서 내 API 키를 가져 왔으며 YOUR_KEY_HERE 영역 내에 google_maps_API.xml (디버그)에 API 키를 배치했습니다. AndroidManifest에서 볼 수 있습니다. 그런 다음 앱을 빌드/실행하고 충돌합니다.ConstraintLayout 내부에 GoogleMap을 표시하는 방법은 무엇입니까?

아직 코드를 작성하지 않았습니다. 안드로이드 모니터에 따르면

여기에 충돌 보고서입니다 :

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference 
               at com.example.mikedouglas.maps.MapsActivity.onCreate(MapsActivity.java:24) 

그래서 나는 MapsActivity.java:24 클릭하고는 다음 날 취합니다!

[[] 여기에 이미지 설명을 입력 [1]

아직 코드를 건드리지 않았으며, 방금이 새로운 프로젝트를 만들었고, 필자가 예상했던 곳에 API 키를 추가하고 빌드/실행을 클릭 한 다음 충돌합니다. 이것은 Google이 작성한 코드가 모두 충돌하는 것입니다.

사람들이 말하는 것처럼 StackOverflow를보고 getSupportFragmentManager에서 getChildFragmentManager로 변경하려고 시도했지만 작동하지 않습니다.

activity_maps.xml 파일 :

<android.support.constraint.ConstraintLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/map" 
android:name="com.google.android.gms.maps.SupportMapFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.mikedouglas.maps.MapsActivity" /> 

문제점은 무엇입니까? 무엇을 바꾸어야합니까?

편집 :

태그는 레이아웃 파일이 런타임에 다른 레이아웃을 동적으로 포함시킬 수 있습니다. 레이아웃 편집시 특정 레이아웃을 사용할 수 없습니다. 레이아웃을 편집하는 동안 미리보기를 원하는 레이아웃을 선택할 수 있습니다.

  • < 조각 com.google.android.gms.maps.SupportMapFragment ...> (레이아웃 선택) 당신은 ConstraintLayout 내부의 조각을 둘 필요가
+0

'activity_maps.xml'에있는 것을 (텍스트가 아닌 텍스트로) 보여주세요. –

+0

xml 파일에서 android : name = "com.google.android.gms.maps.SupportMapFragment"를 찾고 있다고 생각합니다. – iBEK

+0

Fragment를 ContraintLayout으로 변경 했습니까? –

답변

1

:

<android.support.constraint.ConstraintLayout  
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.mikedouglas.maps.MapsActivity"> 

    <fragment 
     android:id="@+id/map" 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</android.support.constraint.ConstraintLayout> 
+0

Google지도가 에뮬레이터에서 작동하지 않습니까? – iBEK

+0

조각 추가와 함께 새로운 오류가 발생했습니다. 아래 "편집"코드에서 편집했습니다. 이를 없애기 위해 무엇을 할 수 있습니까? – iBEK

+0

@iBEK Android Studio 미리보기에서 렌더링 문제 일뿐입니다. Android Studio에서 SupportMapFragment를 렌더링 할 수 없습니다 (https://stackoverflow.com/questions/23898992/android-studio-google-map-v2-fragment-rendering). 무시할 수 있습니다. 앱이 실행 중입니다. –