0

Je charge une image en utilisant la bibliothèque Universal Image Loader, et j'ai obtenu cette exception. Je ne pouvais pas comprendre la cause de cette exception. Quelqu'un peut-il aider? Merci d'avance.java.lang.IllegalArgumentException: la vue ne doit pas être nulle; lors de l'implémentation de la fonction UIL displayImage dans Android

E/j v .lang.Illegal ArgumentException: view must not be null 
E/j v .l ng.Illeg l rgumentException: java .lang.Illegal ArgumentException: view must not be null 
E/j v .l ng.Illeg l rgumentException:  t com.nostra13.universalimageloader.core.im ge w re.View w re.<init>(View w re.j v :70) 
E/j v .l ng.Illeg l rgumentException:  t com.nostr 13.univers lim gelo der.core.im ge w re.View w re.<init>(View w re.j v :50) 
E/j v .l ng.Illeg l rgumentException:  t com.nostr 13.univers lim gelo der.core.im ge w re.Im geView w re.<init>(Im geView w re.j v :44) 
E/j v .l ng.Illeg l rgumentException:  t com.nostr 13.univers lim gelo der.core.Im geLo der.displ yIm ge(Im geLo der.j v :303) 
E/j v .l ng.Illeg l rgumentException:  t project1.ri fy.com.im gecentercrop.M in ctivity.im gePopupWindow(M in ctivity.j v :219) 
E/j v .l ng.Illeg l rgumentException:  t project1.ri fy.com.im gecentercrop.M in ctivity$2.onClick(M in ctivity.j v :143) 
E/j v .l ng.Illeg l rgumentException:  t ndroid.view.View.performClick(View.j v :4232) 
E/j v .l ng.Illeg l rgumentException:  t ndroid.view.View$PerformClick.run(View.j v :17298) 
E/j v .l ng.Illeg l rgumentException:  t ndroid.os.H ndler.h ndleC llb ck(H ndler.j v :615) 
E/j v .l ng.Illeg l rgumentException:  t ndroid.os.H ndler.disp tchMess ge(H ndler.j v :92) 
E/j v .l ng.Illeg l rgumentException:  t ndroid.os.Looper.loop(Looper.j v :137) 
E/j v .l ng.Illeg l rgumentException:  t ndroid. pp. ctivityThre d.m in(ctivityThre d.j v :4921) 
E/j v .l ng.Illeg l rgumentException:  t j v .l ng.reflect.Method.invokeN tive(N tive Method) 
E/j v .l ng.Illeg l rgumentException:  t j v .l ng.reflect.Method.invoke(Method.j v :511) 
E/j v .l ng.Illeg l rgumentException:  t com. ndroid.intern l.os.ZygoteInit$Method nd rgsC ller.run(ZygoteInit.j v :1027) 
E/j v .l ng.Illeg l rgumentException:  t com. ndroid.intern l.os.ZygoteInit.m in(ZygoteInit.j v :794) 
E/j v .l ng.Illeg l rgumentException:  t d lvik.system.N tiveSt rt.m in(N tive Method) 
E/Sp nn bleStringBuilder: SP N_EXCLUSIVE_EXCLUSIVE sp ns cannot h ve zero length 
E/Sp nn bleStringBuilder: SP N_EXCLUSIVE_EXCLUSIVE sp ns cannot h ve zero length 

J'essayais d'afficher une image dans une fenêtre surgissante. Ceci est mon code:

public void imagePopupWindow(ArrayList<String> imageList) { 
    try { 
     final PopupWindow pwindotwo; 

     LayoutInflater inflater = (LayoutInflater) MainActivity.this 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.popupmenu, 
       (ViewGroup) findViewById(R.id.popup_element)); 
     pwindotwo = new PopupWindow(layout, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true); 

     ImageLoader imageLoader = ImageLoader.getInstance(); 
     DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true) 
       .cacheOnDisc(true).resetViewBeforeLoading(true).build(); 

     ImageView imageView= (ImageView) findViewById(R.id.imgView2);; 

     String array[] = new String[imageList.size()]; 

     try { 
      for (int j = 0; j <imageList.size(); j++) { 
       array[j] = imageList.get(j); 
      } 
     } 
     catch (Exception e) { 
      Log.e(e.getClass().getName(), e.getMessage(),e); 
     } 

     for(int j=0;j<imageList.size();j++) { 

      try { 
       imageLoader.displayImage(array[j], imageView, options); 
       Log.e("gg", "arraylist" + array); 
      } 
      catch (Exception e){ 
       Log.e(e.getClass().getName(), e.getMessage(),e); 
      } 
     } 

     pwindotwo .setOutsideTouchable(true); 
     pwindotwo .setBackgroundDrawable(new ShapeDrawable()); 
     pwindotwo .setTouchInterceptor(new View.OnTouchListener() { // or whatever you want 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       if (event.getAction() == MotionEvent.ACTION_OUTSIDE) 
       { 
        pwindotwo .dismiss(); 
        return true; 
       } 
       return false; 
      } 
     }); 

     pwindotwo.showAtLocation(layout, Gravity.CENTER_VERTICAL, 0, 0); 
     pwindotwo.showAsDropDown(layout); 
     pwindotwo.setFocusable(true); 
    } 
    catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

Répondre

1

En conséquence la stacktrace

ImageView imageView= (ImageView) findViewById(R.id.imgView2);; 

est nulle. C'est probablement une partie du layout que vous avez gonflé. Changez-le avec

ImageView imageView= (ImageView) layout.findViewById(R.id.imgView2);; 
+0

Vous voulez dire ImageView imageView = (ImageView) R.layout.popupmenu.findViewById (R.id.imgView2); ce ?? – Tom

+0

mon nom de fichier de mise en page est "popupmenu" – Tom

+0

dans quelle mise en page avez-vous mis le ImageView? – Blackbelt