我想從解析雲中下載圖像並將它們加載到地圖圖標中。我正在使用畢加索將圖像轉換爲位圖。我第一次使用地圖,我不確定我的方法是否正確將圖像加載到地圖圖標中。請有人幫助我!從解析加載圖像時發生NullPointerException
markerOpts =
markerOpts.title(post.getText());
String uri = post.getImage().getUrl();
final MarkerOptions finalMarkerOpts = markerOpts;
Picasso.with(context)
.load(uri)
.into(new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
/* Save the bitmap or do something with it here */
//Set it in the ImageView
finalMarkerOpts.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
// }
// Add a new marker
Marker marker = mapFragment.getMap().addMarker(markerOpts);
mapMarkers.put(post.getObjectId(), marker);
// if (post.getObjectId().equals(selectedPostObjectId)) {
// marker.showInfoWindow();
// selectedPostObjectId = null;
// }
}
// Clean up old markers.
cleanUpMarkers(toKeep);
}
});
}
解析模型
public ParseFile getImage(){
return getParseFile("Image");
}
的logcat:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.parse.ParseFile.getUrl()' on a null object reference
at com.google.mywall.MainActivity$2.done(MainActivity.java:688)
at com.google.mywall.MainActivity$2.done(MainActivity.java:627)
在這裏發佈logcat垃圾。 –
'post.getImage()。getUrl();'檢查並放入try catch。 –
@Clara我如何創建parsefile的日誌? – Savita