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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:22:12+00:00 2026-05-23T14:22:12+00:00

I am trying to implement the android gallery example from http://developer.android.com/resources/tutorials/views/hello-gallery.html I get this

  • 0

I am trying to implement the android gallery example from http://developer.android.com/resources/tutorials/views/hello-gallery.html

I get this error int he following lines

       R.drawable.sample_1 cannot be resolved
        R.drawable.sample_2 cannot be resolved,
        R.drawable.sample_3 cannot be resolved,
        R.drawable.sample_4 cannot be resolved,
        R.drawable.sample_5 cannot be resolved,
        R.drawable.sample_6 cannot be resolved,
        R.drawable.sample_7 cannot be resolved

How to resolve this issue .The code is shown below.

HelloGallery.java

  package com.HelloGallery;

  import android.app.Activity;
  import android.content.Context;
  import android.content.res.TypedArray;
  import android.os.Bundle;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.Gallery;
  import android.widget.ImageView;
  import android.widget.Toast;
  import android.widget.AdapterView.OnItemClickListener;
  import android.R.drawable;

  public class HelloGalleryActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     Gallery g = (Gallery) findViewById(R.id.gallery);
     g.setAdapter(new ImageAdapter(this));

     g.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(AdapterView parent, View v, int position, long id) {
        Toast.makeText(HelloGalleryActivity.this, "" + position, Toast.LENGTH_SHORT).show();
         }
     });


      }

      public class ImageAdapter extends BaseAdapter {
     int mGalleryItemBackground;
     private Context mContext;

     private Integer[] mImageIds = {
        R.drawable.sample_1,
        R.drawable.sample_2,
        R.drawable.sample_3,
        R.drawable.sample_4,
        R.drawable.sample_5,
        R.drawable.sample_6,
        R.drawable.sample_7
     };

     public ImageAdapter(Context c) {
         mContext = c;
         TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
         mGalleryItemBackground = a.getResourceId(
            R.styleable.HelloGallery_android_galleryItemBackground, 0);
         a.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 i = new ImageView(mContext);

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

         return i;
     }
      }
  }

main.mxml

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
  <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/hello"
      />
      <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/gallery"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
  />
  </LinearLayout>

attrs.mxml

  <?xml version="1.0" encoding="utf-8"?>
  <resources>
      <declare-styleable name="HelloGallery">
     <attr name="android:galleryItemBackground" />
      </declare-styleable>
  </resources>

R.java

  /* AUTO-GENERATED FILE.  DO NOT MODIFY.
   *
   * This class was automatically generated by the
   * aapt tool from the resource data it found.  It
   * should not be modified by hand.
   */

  package com.HelloGallery;

  public final class R {
      public static final class attr {
      }
      public static final class drawable {
     public static final int icon=0x7f020000;
      }
      public static final class id {
     public static final int gallery=0x7f050000;
      }
      public static final class layout {
     public static final int main=0x7f030000;
      }
      public static final class string {
     public static final int app_name=0x7f040001;
     public static final int hello=0x7f040000;
      }
      public static final class styleable {
     /** Attributes that can be used with a HelloGallery.
        <p>Includes the following attributes:</p>
        <table>
        <colgroup align="left" />
        <colgroup align="left" />
        <tr><th>Attribute</th><th>Description</th></tr>
        <tr><td><code>{@link #HelloGallery_android_galleryItemBackground com.HelloGallery:android_galleryItemBackground}</code></td><td></td></tr>
        </table>
        @see #HelloGallery_android_galleryItemBackground
      */
     public static final int[] HelloGallery = {
         0x0101004c
     };
     /**
       <p>This symbol is the offset where the {@link com.HelloGallery.R.attr#android_galleryItemBackground}
       attribute's value can be found in the {@link #HelloGallery} array.
       @attr name android:android_galleryItemBackground
     */
     public static final int HelloGallery_android_galleryItemBackground = 0;
      };
  }
  • 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-23T14:22:13+00:00Added an answer on May 23, 2026 at 2:22 pm

    You haven’t got files in your /res/drawable folder with the names

    sample_1.png … _7 etc

    These are needed to populate the widget, you are declaring you use them here:

     private Integer[] mImageIds = {
        R.drawable.sample_1,
        R.drawable.sample_2,
        R.drawable.sample_3,
        R.drawable.sample_4,
        R.drawable.sample_5,
        R.drawable.sample_6,
        R.drawable.sample_7
     };
    

    This is an array of integers, each integer is an ID relating to a drawable resource that you should have created into your /res/drawable folder.

    If you want to get it to work quickly just copy and paste the icon.png file that is already in the /drawable/ folder and rename the paste sample_1.png, sample_2.png, sample_3.png etc

    If you did have these file they would be linked in your R.java class file

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

Sidebar

Related Questions

I am trying to implement the GridView tutorial at: http://developer.android.com/resources/tutorials/views/hello-gridview.html However, I get the
I've been trying to implement the tab UI described in this tutorial: https://developer.android.com/resources/tutorials/views/hello-tabwidget.html I
I am trying to implement this example http://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html and i have followed exactly all
I am trying to implement this multi-touch android tutorial http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-5-implementing-the-drag-gesture/1789?tag=mantle_skin;content I am stuck in
I'm currently trying to implement SeekBarPreference class using http://android-journey.blogspot.com/2010/01/for-almost-any-application-we-need-to.html tutorial with RelativeLayout. First problem
I am trying to implement a segmentated radio button from here: https://github.com/makeramen/android-segmentedradiobutton but I
I am trying to implement Camera application in android,and i got some code from
I am trying implement a photo gallery similar to facebook in Android. I was
I am trying to implement swipe in android from left to right and right
I am trying to implement Fragments in my Project using the https://github.com/JakeWharton/Android-ViewPagerIndicator plugin. My

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.