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 7650043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:09:03+00:00 2026-05-31T11:09:03+00:00

I did check those posts about Infinite gallery before posting this question but it

  • 0

I did check those posts about Infinite gallery before posting this question but it didn’t work for me. The gallery remained as it was. This piece of code : gallery.setSelection((int)(Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2)% mImageIds.length); doesn’t affect the gallery even a bit. And whats more,instead of defining the gallery items in the onCreate itself just for getting the length for above setSelection() statement,I just wrote 7 instead of mImageIds.length since my gallery contains 7 items. But the LogCat started showing ArrayIndexOutOfBounds Exception. So what choice did I have? I did what everyone would do. I removed that 7 and undid the code to the point where it was running fine. But again,the LogCat didn’t come out of that error. It really is frustating. Please help.

And it will be a lot helpful if someone can help with the Endless Gallery.

Thanking you in anticipation.

LogCat :

03-17 18:46:09.681: D/android.widget.GridLayout(626): horizontal constraints: x7 – x0 > 320, x4 – x3 > 87, x5 – x4 > 0, x6 – x5 > 77, x4 – x2 < 64, x4 – x3 < 64, x2 – x1 < 64, x1 – x0 < 64 are inconsistent; permanently removing: x7 – x0 < 320, x4 – x2 < 64, x4 – x3 < 64.
03-17 18:46:09.691: D/android.widget.GridLayout(626): vertical constraints: y1 – y0 > 21, y2 – y1 > 45, y3 – y2 > 42, y4 – y3 > 40, y5 – y4 > 10, y6 – y5 > 48, y7 – y6 > 0, y8 – y7 > 48, y9 – y8 > 0, y10 – y9 > 48, y11 – y10 > 0, y12 – y11 > 44, y12 – y10 > 48, y13 – y12 > 82, y13 – y0 < 199, y12 – y11 < 44 are inconsistent; permanently removing: y13 – y0 < 199.
03-17 18:46:09.751: D/AndroidRuntime(626): Shutting down VM
03-17 18:46:09.751: W/dalvikvm(626): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
03-17 18:46:09.771: E/AndroidRuntime(626): FATAL EXCEPTION: main
03-17 18:46:09.771: E/AndroidRuntime(626): java.lang.ArrayIndexOutOfBoundsException: length=7; index=1073741823
03-17 18:46:09.771: E/AndroidRuntime(626): at com.sanjay.frames.FramesActivity$ImageAdapter.getView(FramesActivity.java:86)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.Gallery.makeAndAddView(Gallery.java:844)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.Gallery.layout(Gallery.java:645)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.Gallery.onLayout(Gallery.java:346)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.View.layout(View.java:11278)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.View.layout(View.java:11278)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.View.layout(View.java:11278)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.View.layout(View.java:11278)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.View.layout(View.java:11278)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.os.Handler.dispatchMessage(Handler.java:99)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.os.Looper.loop(Looper.java:137)
03-17 18:46:09.771: E/AndroidRuntime(626): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-17 18:46:09.771: E/AndroidRuntime(626): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 18:46:09.771: E/AndroidRuntime(626): at java.lang.reflect.Method.invoke(Method.java:511)
03-17 18:46:09.771: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-17 18:46:09.771: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-17 18:46:09.771: E/AndroidRuntime(626): at dalvik.system.NativeStart.main(Native Method)

Here’s the code for my gallery :

public class FramesActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   DisplayMetrics metrics=new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    Gallery gallery = (Gallery) findViewById(R.id.gallery);
    Integer[] mImageIds = {
            R.drawable.ic_launcher,
            R.drawable.ic_menu_template,
            R.drawable.th,
            R.drawable.wt,
            R.drawable.cur,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher
    };     

    gallery.setAdapter(new ImageAdapter(this));
    gallery.setSelection((int)(Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2)%       mImageIds.length);

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            EditText editText2=(EditText) findViewById(R.id.editText2);
            editText2.setText(""+position);
        }
    });
}
public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;

    private Integer[] mImageIds = {
            R.drawable.ic_launcher,
            R.drawable.ic_menu_template,
            R.drawable.th,
            R.drawable.wt,
            R.drawable.cur,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher
    };

    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.Frames);
        mGalleryItemBackground = attr.getResourceId(
                R.styleable.Frames_android_galleryItemBackground, 0);
        attr.recycle();
    }

    public int getCount() {
        return mImageIds.length;
    }

    public Object getItem(int position) {
        return position;
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);

        imageView.setImageResource(mImageIds[position]);
        imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(mGalleryItemBackground);

        return imageView;
    }
}   
}

Also,I am a newbie in android development.So if you see any other mistake in the above code,don’t mind pointing them out.

  • 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-31T11:09:05+00:00Added an answer on May 31, 2026 at 11:09 am

    You should pass the list to your adapter like so (or use an ArrayAdapter):

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       DisplayMetrics metrics=new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        Gallery gallery = (Gallery) findViewById(R.id.gallery);
        Integer[] mImageIds = {
                R.drawable.ic_launcher,
                R.drawable.ic_menu_template,
                R.drawable.th,
                R.drawable.wt,
                R.drawable.cur,
                R.drawable.ic_launcher,
                R.drawable.ic_launcher
        };     
    
        gallery.setAdapter(new ImageAdapter(this, mImageIds));
        gallery.setSelection((int)(Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2)%       mImageIds.length);
    
        gallery.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position, long id) {
                EditText editText2=(EditText) findViewById(R.id.editText2);
                editText2.setText(""+position);
            }
        });
    }
    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;
        private Context mContext;
    
        private Integer[] mImageIds = null;
    
        public ImageAdapter(Context c, Integer[] imageIds) {
            mContext = c;
            mImageIds = imageIds;
            TypedArray attr = mContext.obtainStyledAttributes(R.styleable.Frames);
            mGalleryItemBackground = attr.getResourceId(
                    R.styleable.Frames_android_galleryItemBackground, 0);
            attr.recycle();
        }
    
        public int getCount() {
            return (mImageIds != null) ? mImageIds.length : 0;
        }
    // etc
    

    if that’s not helping post the error from the log and highlight the line where it happens.

    Edit:

    gallery.setSelection((int)(Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2)%       mImageIds.length);
    

    is causing the Error.
    (2000 / 2) – (2000 / 2) % 7 = 1000 – 1000 % 7 = 1000 – (1000 % 7) = 1000 – 6 = Way too big.

    The result must be 0..6 if mImageIds.size == 7

    What should that line do?

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

Sidebar

Related Questions

First, I did check this post but it is in Python, first, and second
Fair warning: I am no expert, but I did manage to get this far.
I have read several posts on this topic, but have yet to find a
I did a quick search on how to check whether Internet is available or
I have opended a question about repeated parameter-checks in public methods. The result there
This is a bit of a weird desire but I am making a matching
This one is pretty crazy: I've got an AppSight recording (for those not familiar,
my script should do this: Check if there is a $startprice and $endprice for
Got asked this interesting interview question today. Explain in detail the process by which
On my website I did not wan't to use those distorted text CAPTCHAS. So

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.