“IBitmapDescriptorFactory가 초기화되지 않았습니다.”오류
Google Maps Android API v2에서 맞춤 아이콘이있는 마커를 얻으려고합니다. Google에서 제공하는 예제 중 하나를 변경했습니다. .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow))
메서드에서 RawMapViewDemoActivity에 추가 했습니다.setUpMap().
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((MapView) findViewById(R.id.map)).getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
}
하지만 항상 "IBitmapDescriptorFactory가 초기화되지 않았습니다"라는 메시지가 나타납니다.
12-18 15:40:54.356: E/AndroidRuntime(12591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapdemo/com.example.mapdemo.RawMapViewDemoActivity}: java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.os.Looper.loop(Looper.java:137)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-18 15:40:54.356: E/AndroidRuntime(12591): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 15:40:54.356: E/AndroidRuntime(12591): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-18 15:40:54.356: E/AndroidRuntime(12591): at dalvik.system.NativeStart.main(Native Method)
12-18 15:40:54.356: E/AndroidRuntime(12591): Caused by: java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.google.android.gms.internal.at.a(Unknown Source)
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.google.android.gms.maps.model.BitmapDescriptorFactory.d(Unknown Source)
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.google.android.gms.maps.model.BitmapDescriptorFactory.fromResource(Unknown Source)
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.example.mapdemo.RawMapViewDemoActivity.setUpMap(RawMapViewDemoActivity.java:67)
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.example.mapdemo.RawMapViewDemoActivity.setUpMapIfNeeded(RawMapViewDemoActivity.java:58)
12-18 15:40:54.356: E/AndroidRuntime(12591): at com.example.mapdemo.RawMapViewDemoActivity.onCreate(RawMapViewDemoActivity.java:43)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.Activity.performCreate(Activity.java:5008)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-18 15:40:54.356: E/AndroidRuntime(12591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-18 15:40:54.356: E/AndroidRuntime(12591): ... 11 more
에서 BitmapDescriptorFactory 는 말합니다 :
이 클래스의 메서드를 사용하기 전에 다음 중 하나를 수행하여이 클래스가 초기화되었는지 확인해야합니다.
애플리케이션에 추가 한 MapFragment 또는 MapView에서 GoogleMap을 사용할 수있을 때까지 기다립니다. getMap () 메소드를 호출하고 반환 된 객체가 null이 아닌지 확인하여 GoogleMap을 사용할 수 있는지 확인할 수 있습니다.
Call MapsInitializer.initialize(Context). As long as a com.google.android.gms.common.GooglePlayServicesNotAvailableException GooglePlayServicesNotAvailableException isn't thrown, this class will be correctly initialized.
I did the first one, but still getting this error. Any suggestions?
Call MapsInitializer.initialize(getApplicationContext())
in the onCreate()
Call following in onCreate()
try {
MapsInitializer.initialize(getApplicationContext());
} catch (GooglePlayServicesNotAvailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Move your code to be called 'onMapReady()', a callback provided by the GoogleMaps API.
It will work!
This happened to me and finally In my case what I could find was the google play services were not installed. So installed them and app did not crash. So may be one can put try and a dialog saying so in the catch block.
See Custom marker in google maps in android with vector asset icon.
In my case I had markers over Google Maps. But on API 19 emulator there is a problem with Google Play Services
. So this error is misleading, Google Play Services
tried to create BitmapDescriptor
, but could not.
You should create markers in onMapReady()
, also move there any other code, working with Google Maps
.
If you have problems with showing Google Maps on Android 4, maybe you should downgrade a library from 16.1.0 to 16.0.0, see https://stackoverflow.com/a/54772374/2914140. But if you do so, you will get a crash on Androif 9, see Google Maps crashing on Android Pie.
GoogleApiAvailability googleApiAvailability=GoogleApiAvailability.getInstance();
int status=googleApiAvailability.isGooglePlayServicesAvailable(getActivity());
if (status != ConnectionResult.SUCCESS) {
int requestCode = 10;
Dialog dialog = googleApiAvailability.getErrorDialog(getActivity(),status,requestCode);
dialog.show();
}else {}
참고URL : https://stackoverflow.com/questions/13935725/ibitmapdescriptorfactory-is-not-initialized-error
'Program Tip' 카테고리의 다른 글
프로그래밍 방식으로 ImageView 표시 (0) | 2020.12.03 |
---|---|
한 데이터베이스에서 다른 데이터베이스로 데이터 전송 (0) | 2020.12.03 |
양식 제출 전 Jquery 함수 (0) | 2020.12.03 |
ansible : 여러 명령을 전달하는 방법 (0) | 2020.12.03 |
C #에서 Excel 파일을 여는 방법은 무엇입니까? (0) | 2020.12.03 |