我需要使用ImageView
位图配置ImagePrincipal
(imageBackground),但在将位图传递给NullPointerException
imageBackground
)
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
ViewPager pager = (ViewPager) container;
View view = LayoutInflater.from(context).inflate(R.layout.slider_image_perfil_adapter, null);
// final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar2);
final ImageView imagePrincipal = (ImageView) view.findViewById(R.id.imagePrincipal);
final ImageView imageBackground = (ImageView) view.findViewById(R.id.imagebackground);
pager.addView(view);
if (!images.get(position).getUrl().equals("")) {
Picasso.with(context).load(images.get(position).getUrl()).fit().centerInside().into(imagePrincipal, new Callback() {
@Override
public void onSuccess() {
try {
if (imagePrincipal.getDrawable() != null) {
Bitmap bitmap = ((BitmapDrawable) imagePrincipal.getDrawable()).getBitmap();
imagePrincipal.setImageBitmap(bitmap);
if (!isExibicaoPortifolioActivity) {
bitmap = criarEfeitoBlur(bitmap, 25.0 f);
if (bitmap != null) {
//Drawable drawable = new BitmapDrawable(imagePrincipal.getContext().getResources(), bitmap);
//imagePrincipal.setBackground(drawable);
imageBackground.setImageBitmap(bitmap); //This erro ocurred in this line
}
}
}
} catch (Exception ex) {
Toast.makeText(context, ex.getMessage(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onError() {
Log.e("Picasso", "onError: ");
}
});
}
return view;
}
答案 0 :(得分:0)
在public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
中设置位图时,您获得了[Authorize]
public class HomeController : Controller
{
public ActionResult Index()
{
return View((User as ClaimsPrincipal).Claims);
}
}
。根据您的代码,您检查NullPointerException
是否为空。所以怀疑你的ImageView
是空的。
确保Bitmap
的ID正确无误且存在于ImageView
布局中。