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

  • SEARCH
  • Home
  • 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 7793215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:24:55+00:00 2026-06-01T22:24:55+00:00

I have infinite gallery based on this example : http://blog.blundell-apps.com/infinite-scrolling-gallery/ , every thing run

  • 0

I have infinite gallery based on this example :

http://blog.blundell-apps.com/infinite-scrolling-gallery/, every thing run ok :

exactly i want to applied text to each image and able to customize text too as shown down image ,and each image has diffrenet text than others , but still not succeed to do it with infinite gallery

enter image description here

I tried with following code but it gave me FORCE CLOSE when running the app ,

( MAYBE THERE IS WRONG CODES I WROTE , BUT IM STILL LEARNING JAVA AND BEGINER IN ANDROID DEVELOPMENT) .

please any help and advice will be appreciated

THANKS ALOT.

MY CODE :

GALLERY_ITEM

<?xml version="1.0" encoding="utf-8"?> 
  <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"   
      android:id="@+id/LinearLayout01" 
      android:layout_width="fill_parent"   
      android:layout_height="fill_parent" 
      android:orientation="vertical"   
      android:gravity="center_horizontal">  
  <ImageView  
     android:id="@+id/image" 
     android:layout_height="300dp" 
     android:layout_width="fill_parent"          /> 
  <TextView   
    android:text="TextView" 
    android:id="@+id/textView1"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:textColor="#B22222"    
    android:textSize="20dp"   
    android:gravity="center"   
    android:layout_margin="30dp"  
    android:layout_below="@+id/image"          />  

Then change in InfiniteScrollingGalleryActivity.java as follow :

  public class InfiniteScrollingGalleryActivity extends Activity {  

     /** Called when the activity is first created. */  
   @Override 
     public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
        // Set the layout to use   
     setContentView(R.layout.main);  

   InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne); 
   galleryOne.setAdapter(new InfiniteGalleryAdapter(this));    
        }      } 

Then change the InfiniteGalleryResourceAdapter.java as follow :

 public class InfiniteGalleryAdapter extends BaseAdapter {

    /** The width of each child image */  
   private static final int G_ITEM_WIDTH = 360; 
   /** The height of each child image */  
  private static final int G_ITEM_HEIGHT = 240; 
  /** The context your gallery is running in (usually the activity) */ 
       private Context mContext;  
       private int imageWidth; 
       private int imageHeight;  
       private int[] imageIds;  

      public InfiniteGalleryAdapter(Context c, int[] imageIds) { 
            this.mContext = c;  
            this.imageIds = imageIds; }

      public int getCount() {   
        return Integer.MAX_VALUE;     } 
      public Object getItem(int position) { 
        return position;    } 
      public long getItemId(int position) {  
        return position;    }      

      private Activity activity;   
      private  LayoutInflater inflater=null; 

   public InfiniteGalleryAdapter(Activity a) {     
      final int[] imageIds;
     activity = a;  
     inflater = (LayoutInflater)activity.getSystemService
          Context.LAYOUT_INFLATER_SERVICE);          }   
      public  class ViewHolder{    
      public TextView text;     
      public ImageView image;         }  
  public View getView(int position, View convertView, ViewGroup parent) {  
     ImageView i = getImageView();  
 try {  

   int itemPos = (position % imageIds.length); 

   i.setImageResource(imageIds[itemPos]); 

  ((BitmapDrawable) i.getDrawable()).setAntiAlias(true); }

          catch (OutOfMemoryError e) {  

    Log.e("InfiniteGalleryResourceAdapter", "Out of memory creating imageview. 
        Using empty view.", e);     }  

     View vi=convertView; 

      ViewHolder holder;   

     if(convertView==null){   
        vi = inflater.inflate(R.layout.gallery_items, null);   
    holder=new ViewHolder();  
    holder.text=(TextView)vi.findViewById(R.id.textView1); 
    holder.image=(ImageView)vi.findViewById(R.id.image);      
    vi.setTag(holder);             }  
    else    
    holder=(ViewHolder)vi.getTag(); 
    holder.text.setText(name[position]);  

   final int stub_id=images[position]; 
   holder.image.setImageResource(stub_id);  
  return vi;         }

    private int[] images = {   
         R.drawable.one_1, R.drawable.one_4,  
         R.drawable.one_2, R.drawable.one_5, 
         R.drawable.one_3                    }; 

   private String[] name = {   
         "this is my car", "i love this",   
         "please hekp me", "im in park", 
         " This is nice place to visit.",          }; 


   private ImageView getImageView() {  
      setImageDimensions();  
     ImageView i = new ImageView(mContext);  
     i.setLayoutParams(new Gallery.LayoutParams(imageWidth, imageHeight)); 
     i.setScaleType(ScaleType.CENTER_INSIDE);     return i;      } 

 private void setImageDimensions() {   
      if (imageWidth == 0 || imageHeight == 0) {   
     imageWidth = AndroidUtils.convertToPix(mContext, G_ITEM_WIDTH);  
     imageHeight = AndroidUtils.convertToPix(mContext,G_ITEM_HEIGHT); 
        }         }      
           } 

This is logcat error :

04-10 02:25:13.057: E/AndroidRuntime(12302): FATAL EXCEPTION: main
04-10 02:25:13.057: E/AndroidRuntime(12302): java.lang.NullPointerException
04-10 02:25:13.057: E/AndroidRuntime(12302):
at com.infinite.test.AndroidUtils.convertToPix(AndroidUtils.java:11)
04-10 02:25:13.057: E/AndroidRuntime(12302): 
at com.infinite.test.InfiniteGalleryAdapter.setImageDimensions
(InfiniteGalleryAdapter.java:131)
4-10 02:25:13.057: E/AndroidRuntime(12302):
at com.infinite.test.InfiniteGalleryAdapter.getImageView
(InfiniteGalleryAdapter.java:117)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at com.infinite.test.InfiniteGalleryAdapter.getView(InfiniteGalleryAdapter.java:66)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.View.measure( View.java:8366)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.View.measure(View.java:8366)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.ViewGroup.measureChildWithMargins(viewGroup.java:3138)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.View.measure(View.java:8366)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.View.measure(View.java:8366)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.View.measure(View.java:8366)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.ViewRoot.performTraversals(ViewRoot.java:844)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.os.Looper.loop(Looper.java:123)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at android.app.ActivityThread.main(ActivityThread.java:3687)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at java.lang.reflect.Method.invokeNative(Native Method)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at java.lang.reflect.Method.invoke    (Method.java:507)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-10 02:25:13.057: E/AndroidRuntime(12302):
at dalvik.system.NativeStart.main(Native Method)
04-10 02:25:13.061: E/(129): Dumpstate > /data/log/dumpstate_app_error
  • 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-06-01T22:24:56+00:00Added an answer on June 1, 2026 at 10:24 pm

    The problem seems to lie with the context variable and position of images. try the following code for your adapter:

    public class InfiniteGalleryAdapter extends BaseAdapter { 
    /** The width of each child image */ 
    private static final int G_ITEM_WIDTH = 360;   
    /** The height of each child image */  
    private static final int G_ITEM_HEIGHT = 240; 
    /** The context your gallery is running in (usually the activity) */   
    private Context mContext;       
    private int imageWidth;     
    private int imageHeight;   
    private int[] imageIds;    
    public InfiniteGalleryAdapter(Context c, int[] imageIds) {    
        this.mContext = c;          
        this.imageIds = imageIds; }   
    public int getCount() {   
        return Integer.MAX_VALUE;   
    }      
    public Object getItem(int position) { 
        return position;    }  
    public long getItemId(int position) { 
        return position;    }       
    //private Activity activity;  
    private  LayoutInflater inflater=null;
    public InfiniteGalleryAdapter(Context a) {  
        final int[] imageIds;  
        //activity = a;   
        this.mContext = a;   
        inflater = (LayoutInflater)mContext.getSystemService   (        Context.LAYOUT_INFLATER_SERVICE);  
    }          public  class ViewHolder{ 
        public TextView text;
        public ImageView image;   
    }    
    
    private int[] images = {  
            R.drawable.one_1, R.drawable.one_4,   
            R.drawable.one_2, R.drawable.one_5,   
            R.drawable.one_3               
    };    
    private String[] name = {   
            "this is my car", "i love this",   
            "please hekp me", "im in park",    
            " This is nice place to visit.",  
    };       
    public View getView(int position, View convertView, ViewGroup parent) { 
        ImageView i = getImageView(); 
        int itemPos = (position % images.length);  
        try {      
    
            i.setImageResource(images[itemPos]);  
            ((BitmapDrawable) i.getDrawable()).setAntiAlias(true); } 
        catch (OutOfMemoryError e) {     
            Log.e("InfiniteGalleryResourceAdapter", "Out of memory creating imageview.          Using empty view.", e);  
        }         View vi=convertView;     
        ViewHolder holder;  
        if(convertView==null){ 
            vi = inflater.inflate(R.layout.gallery_items, null);  
            holder=new ViewHolder();      
            holder.text=(TextView)vi.findViewById(R.id.textView1);   
            holder.image=(ImageView)vi.findViewById(R.id.image); 
            vi.setTag(holder);    
        }       else   
            holder=(ViewHolder)vi.getTag();  
        holder.text.setText(name[itemPos]); 
        final int stub_id=images[itemPos];  
        holder.image.setImageResource(stub_id); 
        return vi;     
    }   
    
    private ImageView getImageView() { 
        setImageDimensions();   
    
        ImageView i = new ImageView(mContext);   
        i.setLayoutParams(new Gallery.LayoutParams(imageWidth, imageHeight)); 
        i.setScaleType(ScaleType.CENTER_INSIDE);  
        return i;      }  
    private void setImageDimensions() { 
        if (imageWidth == 0 || imageHeight == 0) {        
            imageWidth = AndroidUtils.convertToPix(mContext, G_ITEM_WIDTH);
            imageHeight = AndroidUtils.convertToPix(mContext,G_ITEM_HEIGHT); 
        }         }                  }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have infinite gallery based on this example : http://blog.blundell-apps.com/infinite-scrolling-gallery/ , It runs nicely,
i have created a coverflow using the code given by http://android.jmsliu.com/138/android-infinite-loop-gallery.html . And it
I have an infinite scrolling gallery that uses markup like this (transformed through CSS
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
I have set up infinite scroll on a website I am building here: http://richardgordoncook.com/fg/
I have this code that I found online that does an infinite rotating gallery,
I have an infinite Carousel function applied to a series of images here: http://nokkam.com/showcase.html
I have implemented Infinite scrolling(i.e Load records when the scrollbar reaches the bottom of
I have a PHP script with infinite loop. I need this script running forever.
When redirect to my home page I have an infinite loop. For example is

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.