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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:12:06+00:00 2026-05-20T00:12:06+00:00

I am trying to display pictures that I had placed in the drawable folder

  • 0

I am trying to display pictures that I had placed in the drawable folder using a Gridview. I am getting some errors. My code and the errors I am getting are shown below.

package com.newapp;

import android.R;
import android.R.drawable;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;/*Error here: main cannot be resolved or is not a field*/

import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);/*Error here: main cannot be resolved or is not a field*/

            GridView gridview = (GridView) findViewById(R.id.photogrid);
            gridview.setAdapter(new ImageAdapter(this));

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


    }

public class ImageAdapter extends BaseAdapter {
    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

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

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

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

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

    // references to our images
    private Integer[] mThumbIds = {

            R.drawable.sample_0, /*Error here: sample_0 cannot be resolved and is not a field*/
            R.drawable.sample_1,/*Error here: sample_1 cannot be resolved and is not a field*/
            R.drawable.sample_2,/*Error here: sample_2 cannot be resolved and is not a field*/ 
           R.drawable.sample_3,/*Error here: sample_3 cannot be resolved and is not a field*/
            R.drawable.sample_4,/*Error here: sample_4 cannot be resolved and is not a field*/ 
           R.drawable.sample_5/*Error here: sample_5 cannot be resolved and is not a field*/,
            R.drawable.sample_6, 
           /*Error here: sample_6 cannot be resolved and is not a field*/
    };
}

So can somebody tell me what is causing these problems? Any help will be much appreciated.
Thanks in advance

  • 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-20T00:12:07+00:00Added an answer on May 20, 2026 at 12:12 am

    Here is your first problem: import android.R

    Do not import this as this is the android system’s R package, and not your own project’s R file, hence main cannot be identified, as the R you are referring to for main in the android.R package does not exist.

    If you remove this import, “main” will be recognized, as your own R file will be referenced. The same rule applies for the ImageAdapter. If your remove the import: import android.R.drawable you will avoid the problems you have in this class.

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

Sidebar

Related Questions

I'm trying to display Facebook profile pictures on my site, but don't want to
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
Im trying to display some files in a web page so the user can
I'm trying to display a grayscale TIFF file using Python and MatPlotLib, So far
In my application I want to display some pictures (I need to have them
Im trying to write a very basic android app that displays around 5 pictures
So apparently I'm trying to do something that jQuery does not like. I'm using
I'm currently trying to create a gallery of pictures loaded from Internet. I'm using
I'm trying to display a picture in an openGL environment. The picture's origninal dimensions
Im trying do display my body onload in a div tag, but cant solve

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.