android - Error with random Url image gallery View -


i have made random image gallery view android touch gallery want show random images. have tried generate link random number.

i can not play , have no idea how can solve this.

please help.

activity:

package com.ddd.fun1234;  import java.net.malformedurlexception; import java.net.url; import java.util.arraylist; import java.util.collections; import java.util.list; import java.util.random;  import ru.truba.touchgallery.gallerywidget.galleryviewpager; import ru.truba.touchgallery.gallerywidget.urlpageradapter; import ru.truba.touchgallery.gallerywidget.basepageradapter.onitemchangelistener; import android.app.activity; import android.graphics.bitmap; import android.os.bundle;  public class galleryurlavtivity extends activity {  private galleryviewpager mviewpager;  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main); }  public bitmap getimage() {     random rn = new random();     int n = 200000 - 199000 + 1;     int = rn.nextint() % n;          url tempurl = null;     try {         tempurl = new url("http://miniz.co/ragetoonapp/images/" + rn + ".jpg");     } catch (malformedurlexception e1) {         e1.printstacktrace();     }      list<string> items = new arraylist<string>();     collections.addall(items, tempurl);      urlpageradapter pageradapter = new urlpageradapter(this, items);     pageradapter.setonitemchangelistener(new onitemchangelistener()     {         @override         public void onitemchange(int currentposition)         {          }     });      mviewpager = (galleryviewpager)findviewbyid(r.id.viewer);     mviewpager.setoffscreenpagelimit(3);     mviewpager.setadapter(pageradapter); }  } 

there fail in collections.addall. can use instead of this?

when have idea can or second option, please write it.

daniel

the problem in these lines:

random rn = new random(); ... int = rn.nextint() % n;     ... tempurl = new url("http://miniz.co/ragetoonapp/images/" + rn + ".jpg"); 

you calculating i instead of using in url, you're using rn instead. default, calls random.tostring() contains characters (in case, @) illegal in urls.

to fix should change last line to:

tempurl = new url("http://miniz.co/ragetoonapp/images/" + + ".jpg"); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -