android - NullPointerException for progressbar in fragment for Universal Image Loader in onActivityCreated -



android - NullPointerException for progressbar in fragment for Universal Image Loader in onActivityCreated -

i'm getting unusual npe i'm unable diagnose. know coming referencing progressbar spinner, can't figure out why, because instantiating in oncreateview fragment.

below code fragment. before look, using universal image loader load images. images load, if remove lines of code spinner e.g. spinner.setvisibility(view.gone); spinner.setvisibility(view.visible);

import android.app.activity; import android.graphics.bitmap; import android.net.uri; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.progressbar; import android.widget.textview; import android.widget.toast; import com.nostra13.universalimageloader.core.displayimageoptions; import com.nostra13.universalimageloader.core.imageloader; import com.nostra13.universalimageloader.core.assist.failreason; import com.nostra13.universalimageloader.core.assist.imagescaletype; import com.nostra13.universalimageloader.core.display.fadeinbitmapdisplayer; import com.nostra13.universalimageloader.core.listener.simpleimageloadinglistener; /** * simple {@link fragment} subclass. * activities contain fragment must implement * * handle interaction events. * utilize {@link imagefragment#newinstance} mill method * create instance of fragment. * */ public class imagefragment extends fragment { // todo: rename parameter arguments, take names match private static final string arg_param1 = "param1"; private static final string arg_param2 = "param2"; private int mimagenum; private imageview imagedisplay; private textview texttest; public progressbar spinner; private string murl; private imageloader imageloader = imageloader.getinstance(); displayimageoptions options; /** * utilize mill method create new instance of * fragment using provided parameters. * * @return new instance of fragment imagefragment. */ // todo: rename , alter types , number of parameters public static imagefragment newinstance(int position, string url) { imagefragment fragment = new imagefragment(); bundle args = new bundle(); args.putint(arg_param1, position); args.putstring(arg_param2, url); fragment.setarguments(args); homecoming fragment; } public imagefragment() { // required empty public constructor } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mimagenum = getarguments() != null ? getarguments().getint(arg_param1) : -1; murl = getarguments() != null ? getarguments().getstring(arg_param2) : null; } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { final view v = inflater.inflate(r.layout.fragment_image, container, false); imagedisplay = (imageview) v.findviewbyid(r.id.imageview); spinner = (progressbar) imagedisplay.findviewbyid(r.id.loading); options = new displayimageoptions.builder() .showimageforemptyuri(r.drawable.ic_empty) .showimageonfail(r.drawable.ic_error) .resetviewbeforeloading(true) .cacheondisk(true) .imagescaletype(imagescaletype.exactly) .bitmapconfig(bitmap.config.rgb_565) .considerexifparams(true) .displayer(new fadeinbitmapdisplayer(300)) .build(); homecoming v; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); imageloader.displayimage(murl, imagedisplay, options, new simpleimageloadinglistener() { @override public void onloadingstarted(string imageuri, view view) { spinner.setvisibility(view.visible); } @override public void onloadingfailed(string imageuri, view view, failreason failreason) { string message = null; switch (failreason.gettype()) { case io_error: message = "input/output error"; break; case decoding_error: message = "image can't decoded"; break; case network_denied: message = "downloads denied"; break; case out_of_memory: message = "out of memory error"; break; case unknown: message = "unknown error"; break; } spinner.setvisibility(view.gone); } @override public void onloadingcomplete(string imageuri, view view, bitmap loadedimage) { spinner.setvisibility(view.gone); } }); } }

please help! i'm not fragments, , can't figure out why it's not working

final view v = inflater.inflate(r.layout.fragment_image, container, false); imagedisplay = (imageview) v.findviewbyid(r.id.imageview); spinner = (progressbar) imagedisplay.findviewbyid(r.id.loading);

is "spinner" kid of fragment view or "imagedisplay"?

perhaps, should spinner = (progressbar) v.findviewbyid(r.id.loading);

android nullpointerexception fragment android-progressbar universal-image-loader

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -