1

내가 NullPointerException이NullPointerException가 언제 장소 표시의 방법으로 구글 맵에 마커를 배치 할 때

NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference` 
I/DpmTcmClient: RegisterTcmMonitor from: org.apache.http.impl.conn.TcmIdleTimerMonitor 
W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found. 
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:2 
I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 2 
D/GoogleCertificates: com.google.android.gms.googlecertificates module is loaded 
E/url: http://maps.googleapis.com/maps/api/geocode/json?latlng=35.7742618,51.3596331&sensor=true 
E/Lat Long to Addresss: 
E/Googlemap: null 
D/GoogleCertificatesImpl: Fetched 363 Google certificates 
I/b: Sending API token request. 
E/b: Authentication failed on the server. 
E/Google Maps Android API: Authorization failure 
Ensure that the "Google Maps Android API v2" is enabled. 
                       Ensure that the following Android Key exists: 

이 또한 내가 getAsyncMap과 OnMapReady가(). 내부 OnMapReady 내가 Asynktask를 호출 익숙해 구글 맵 V2에 마커를 배치하려고 사용자의 위치를 ​​확인하고 onPostExecute 장소 표시 방법은 호출 : 나는 또한 PLS이 link 그리고 012,325에 전체 전체 활동 확인) getAsyncMap로하여 getMap()을 (변경하려고 할 때

public void placeMarker(LatLongDetails user_latlongobj2, 
final Context contextPlace) { 


try { 
if (googlemap == null) { 
    intialiseMap(); 
    animatecamera(user_latlongobj); 
} 
if (LoginDetails.Address.length() < 1) { 
    LoginDetails.Address = "Getting your location ....."; 
} 
googlemap.clear(); 
marker = new MarkerOptions().position(
     new LatLng(user_latlongobj2.user_latitude, 
       user_latlongobj2.user_longitude)).title(
     LoginDetails.Address); 

System.out.println("This is the Address" + LoginDetails.Address); 

marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)); 


googlemap.addMarker(marker).showInfoWindow(); 
System.out.println("PLACING MARKER" + LoginDetails.Address); 
if (marker == null || contextPlace == null) { 
    Intent in =new Intent(this,ProfileActivity1.class); 
    in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    startActivity(in); 
} 
else 
fixmarker(marker, contextPlace); 

} catch (Exception e) { 
fixmarker(marker, contextPlace); 
Log.d("Profileactivity", "" + e); 
    } 

} 

이러한 모든 문제가 함께했다

28,나는 error.here가 로그 캣입니다에 대한 자세한 내용을 찾기 위해 시도 및 캐치를 제거 :

enter code herejava.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference 
                      at android.content.ContextWrapper.getResources(ContextWrapper.java:87) 
                      at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:81) 
                      at android.support.v7.app.AppCompatActivity.getResources(AppCompatActivity.java:551) 
                      at android.content.Context.getString(Context.java:413) 
                      at com.example.cabbookinghome.ProfileActivity1.intialiseMap(ProfileActivity1.java:280) 
                      at com.example.cabbookinghome.ProfileActivity1.placeMarker(ProfileActivity1.java:327) 
                      at epbit.helper.ConversionTaskLatLonLoc.onPostExecute(ConversionTaskLatLonLoc.java:130) 
                      at epbit.helper.ConversionTaskLatLonLoc.onPostExecute(ConversionTaskLatLonLoc.java:24) 
                      at android.os.AsyncTask.finish(AsyncTask.java:651) 
                      at android.os.AsyncTask.access$500(AsyncTask.java:180) 
                      at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
+0

에서하지 액세스 할 수있는 조각하는 방법입니다. – Raghavendra

+0

나는 logcat을 추가했다. –

+0

NLP와 함께 logcat에서 E/Google Maps Android API : Authorization failure "Google Maps Android API v2"가 활성화되어 있는지 확인하십시오. Google의 콘솔을 확인해주세요. – Raghavendra

답변

2

3 일이 검색하고 여기에 작업 한 후에 마지막으로 worked.the 진짜 문제는 GoogleMap으로지도가 시도 및 캐치를 사용 loaded.I하지 않고, 그냥 잡을 예외와 어떻게 안 의미 널 (null)입니다 것입니다 아무것도.

com.google.android.gms.maps.MapFragment.getMap()' on a null object reference 

먼저 내가 그런 getChildFragmentManager()가 해결 될 수 없거나 referenced.using 수 없습니다 나타내는 빨간색이 될 getChildFragmentManager이 링크 Google Map returning nullpointerexception Google Maps Android V2

googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap(); 

을 시도 : 로그인 후 예외가 로그를 확인 나는 이걸 발견 getSupportFragmentManager() 대신이 링크에 설명 된대로 (getChildFragmentManager() cannot be resolved or cannot be referenced)이 문제를 해결하고지도가로드되었습니다.

클래스가 AppCompatActivity에서 확장하는 경우 다음 당신은 getSupportFragmentManager() getChildFragmentManager() 때문에 사용할 필요가 있다는

참고하여 전체 로그 캣을 게시 AppCompatActivity

0

구글 맵 오브젝트 후 if 문을 취소하기 때문이다. googlemap.clear()를 제거하고 시도하십시오.

+0

하지만 googlemap.clear() 뒤에 마커를 추가하고 있습니다. –

+0

nullPoinetException이 계속 발생하려고 시도합니다. –

+0

코드에서 오류를 업데이트하십시오. 나는 그것을 알아 내기 위해 노력할 것이다. –

0

지도가 초기화되지 않거나 위치를 얻지 못합니다. 위치 센서가 활성화되어 있는지 확인하십시오. 그렇지 않은 경우 활성화하십시오. 이 코드를 사용해보십시오.

private void setUpMapIfNeeded() { 
     // Do a null check to confirm that we have not already instantiated the map. 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

    private void setUpMap() { 
     mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); 
     mMap.setMyLocationEnabled(true); 


    } 
+0

getMap은 depreceted이며 대신 getAsyncMap을 사용하려고하면 이러한 문제가 발생합니다. –

관련 문제