Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:03:06+00:00 2026-05-24T09:03:06+00:00

I am retreiving url strings from a text document on a server. Once the

  • 0

I am retreiving url strings from a text document on a server.

Once the images are retreived they are set to a gallery using a ImageAdapter.

 public class ImageAdapter extends BaseAdapter {

           /** The parent context */
       private Context myContext;public ImageAdapter() {
            // TODO Auto-generated constructor stub
            }


                /** URL-Strings to some remote images. */
        public String[] myRemoteImages = {imageUrl,imageUrl2,imageUrl3,imageUrl4};  

        private String[] mImageURLs = {
              "http://www.google.com",
              "http://www.google.com"};






                /** Simple Constructor saving the 'parent' context. */
         public ImageAdapter(Context c) { this.myContext = c; }





                /** Returns the amount of images we have defined. */
          public int getCount() { 
                return this.myRemoteImages.length;
                }




                /* Use the array-Positions as unique IDs */
           public Object getItem(int position) { 
                return position; 
                }


           public long getItemId(int position) { 
                    return position; 
                    }


                /** Returns a new ImageView to
                * be displayed, depending on
                * the position passed. */
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i = new ImageView(this.myContext);

            //  i.setTag(mImageURLs[position]);


                try {


            URL aURL = new URL(myRemoteImages[position]);
            Log.v("ImageLoader", "Remote images set");


            URI imageUri = null;

            //Setting the Uri of aURL to imageUri.
            try {
            imageUri = aURL.toURI();

            } catch (URISyntaxException e1) {
            // TODO Auto-generated catch block
                e1.printStackTrace();
                        }



                //Testing to see if images are already in cache, if not then we load the images from the web and save them to the cache.
           if (new File(new File(myContext.getCacheDir(), "thumbnails"), "" + imageUri.hashCode()).exists())
                           {

        Log.v("Loader", "File exists in cache. Now pulling from the cache");

        String cachFile = myContext.getCacheDir() +"/thumbnails/"+imageUri.hashCode();
        FileInputStream fis;

        try {
        fis = new FileInputStream(cachFile);
        Bitmap bm = BitmapFactory.decodeStream(fis); 
        i.setImageBitmap(bm);

Now the problem is how can i set a URL for each image statically. Meaning that the url’s will change when the images change. How could i possibly go about being able to control what urls are set to an each image?

For example. when a image is clicked, it opens up web browser to a URL set for that particular image.

A Week later the images change, How could i go about changing the url associated with it also?

EDIT: Error i get when using the arrayList of strings.

 08-05 16:56:50.748: ERROR/AndroidRuntime(646): java.lang.ArrayIndexOutOfBoundsException: index=2 length=2
 08-05 16:56:50.748: ERROR/AndroidRuntime(646):     at com.fttech.gameIT.MainMenu$ImageAdapter.getView(MainMenu.java:379)
08-05 16:56:50.748: ERROR/AndroidRuntime(646):     at android.widget.Gallery.makeAndAddView(Gallery.java:748)
08-05 16:56:50.748: ERROR/AndroidRuntime(646):     at android.widget.Gallery.fillToGalleryRight(Gallery.java:700)
08-05 16:56:50.748: ERROR/AndroidRuntime(646):     at android.widget.Gallery.layout(Gallery.java:631)
08-05 16:56:50.748: ERROR/AndroidRuntime(646):     at android.widget.Gallery.onLayout(Gallery.java:339)
08-05 16:56:50.748: ERROR/AndroidRuntime(646):     at android.view.View.layout(View.java:9330)
08-05 16:56:50.748: ERROR/AndroidRuntime(646):     at android.view.ViewGroup.layout(ViewGroup.java:3795)

The error points me here…

    public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i = new ImageView(this.myContext);




                try {


            URL aURL = new URL(myRemoteImages[position]);
            Log.v("ImageLoader", "Remote images set");
            //It points me here  i.setTag(mImageURLs[position]);                    

            URI imageUri = null;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:03:08+00:00Added an answer on May 24, 2026 at 9:03 am

    Create a second ArrayList with String objects (or links if you have a class), each Image will represent itself in that Array via your Adapter.

    For example:

    Image Adapter contains [Image0, Image1, Image2, Image3, Image4],
    While your ArrayList with links contains [Link0, Link1, Link2, Link3, Link4].

    So whenever someone taps an image, you grab the ‘position’, and use it to get your link out of the ArrayList.

    Hope this was helpful to you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm retreiving images from a web server directory like this: WebClient webClientImgDownloader = new
I created an application which reads an xml document from url address. Lately the
I want to make am HTTP GET request from my J2ME application using HttpConnection
I am retrieving a string of values from json url. I have done it
Retrieving data from the REST Server works well, but if I want to post
I have a class which makes a url request and stores data from that
I'm writing code to work with text from Wikipedia and am having issues with
I am retrieving a list of items from a URL and displaying them in
I'm retrieving HTML of many webpages (saved earlier) from SQL Server. My purpose is
i am retrieving data from guardian web service using c#. The answer i get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.