我正在尝试从firebase检索图像,然后将其上传到标记图标。 基于firebase教程中的示例,我成功检索了图像uri,当我将uri放入图像视图时,它可以正常工作,然后我尝试将其放入标记的图标中,但是我得到了错误:
D/AndroidRuntime: Shutting down VM
E/UncaughtException: java.lang.NullPointerException
at maps.f.g.a(Unknown Source)
at maps.af.g$a.<init>(Unknown Source)
at maps.af.g.a(Unknown Source)
at maps.af.R.<init>(Unknown Source)
at maps.af.t.a(Unknown Source)
at vl.onTransact(:com.google.android.gms.DynamiteModulesB:167)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
at com.htaka.mywall.MapsActivity$3.onSuccess(MapsActivity.java:142)
at com.htaka.mywall.MapsActivity$3.onSuccess(MapsActivity.java:137)
at com.google.android.gms.tasks.zze$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5421)
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:914)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
I/DynamiteModule: Considering local module com.google.android.gms.tagmanager:3 and remote module com.google.android.gms.tagmanager:3
I/DynamiteModule: Selected local version of com.google.android.gms.tagmanager
W/GoogleTagManager: Tag Manager's event handler WILL NOT be installed (no container loaded)
I/GoogleTagManager: Tag Manager initilization took 29ms
D/FirebaseCrashApiImpl: throwable java.lang.NullPointerException
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.htaka.mywall, PID: 1013
java.lang.NullPointerException
at maps.f.g.a(Unknown Source)
at maps.af.g$a.<init>(Unknown Source)
at maps.af.g.a(Unknown Source)
at maps.af.R.<init>(Unknown Source)
at maps.af.t.a(Unknown Source)
at vl.onTransact(:com.google.android.gms.DynamiteModulesB:167)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
at com.htaka.mywall.MapsActivity$3.onSuccess(MapsActivity.java:142)
at com.htaka.mywall.MapsActivity$3.onSuccess(MapsActivity.java:137)
at com.google.android.gms.tasks.zze$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5421)
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:914)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
I/Process: Sending signal. PID: 1013 SIG: 9
Application terminated.
我不知道问题是什么......这是我正在使用的代码和类我使用loadImage将其设置为imageview:
public void setMarkers(DataSnapshot dS ,boolean re) {
if(re) {mMap.clear();}
post = dS.getValue(Post.class);
storageRef.child("mountains.jpg").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
ImageView im=new ImageView(MapsActivity.this);
GlideUtil.loadImage(uri.toString(),im );
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(post.latitude, post.longitude))
.title(post.title)
.icon(BitmapDescriptorFactory.fromBitmap(im.getDrawingCache()))
);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
System.out.print("image "+exception.getMessage());
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(post.latitude, post.longitude))
.title(post.title)
);
}
});
PS:如果我删除了图标(BitmapDescriptorFactry ......),应用就会运行它。
这里是loadImage,我是从firebase github部分的示例中得到的,我测试了它并且它工作了,你基本上将uri与imageview一起发送到imageview中,以防有人感兴趣: Gradle:compile&#39; com.github.bumptech.glide:glide:3.6.0&#39;
public class GlideUtil {
public static void loadImage(String url, ImageView imageView) {
Context context = imageView.getContext();
ColorDrawable cd = new ColorDrawable(ContextCompat.getColor(context, R.color.wallet_holo_blue_light));
Glide.with(context)
.load(url)
.placeholder(cd)
.crossFade()
.centerCrop()
.into(imageView);
}
答案 0 :(得分:0)
我想问题是您的im.getDrawingCache()
方法返回null,因为您调用它时ImageView
还没有被测量过。因此,您可以尝试使用preload()
的{{1}}方法和Glide
,并将加载的RequestListener
设置为Bitmap
的图标:
Marker