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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:22:13+00:00 2026-06-06T01:22:13+00:00

I am somewhat new to android development and development in general. I have a

  • 0

I am somewhat new to android development and development in general. I have a custom layout that has a view pager with two pages that can be flipped through horizontally (They work just fine). In the first page, I have a grid view that fills the page. However, I have tried countless different ways to get it to work, but the grid view will not populate with the images and I receive a null pointer exception.

I have a layout file that holds the view pager, and the view pager’s id is fontsviewpager. Then, I have the two separate layouts for the two pages, and the first one has the gridview. The id for the gridview is italiclcgrid.

Here is the Activity:

public class CalligraphyFontsActivity extends Activity implements
    View.OnClickListener {
public Typeface calligraphyfont;
public TextView italiclowercase;

@Override
public void onCreate(Bundle savedInstanceState) {
    SharedPreferences getPrefs = PreferenceManager
            .getDefaultSharedPreferences(getBaseContext());
    boolean fullscreen = getPrefs.getBoolean("fullscreen", true);
    if (fullscreen) {
        setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
    } else {
        setTheme(android.R.style.Theme_NoTitleBar);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.calligraphyfonts2);
    MyPagerAdapter adapter = new MyPagerAdapter();
    ViewPager myPager = (ViewPager) findViewById(R.id.fontsviewpager);
    myPager.setAdapter(adapter);
    myPager.setCurrentItem(0);
    ImageView backhomebutton = (ImageView) findViewById(R.id.backhomebutton);
    ImageView settingspic = (ImageView) findViewById(R.id.settingspic);
    calligraphyfont = Typeface.createFromAsset(getAssets(),
            "fonts/MTCORSVA.TTF");
    settingspic.setOnClickListener(this);
    backhomebutton.setOnClickListener(this);
    GridView gridview = (GridView) findViewById(R.id.italiclcgrid);
    gridview.setAdapter(new ImageAdapter(this));

}

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.capitalagray,
            R.drawable.capitalbgray, R.drawable.capitalcgray };

}

public void onClick(View v) {
    Intent launchsettings = new Intent(CalligraphyFontsActivity.this,
            Settings.class);
    switch (v.getId()) {
    case R.id.backhomebutton:
        finish();
        break;
    case R.id.settingspic:
        startActivity(launchsettings);
        break;

    }
}

public class MyPagerAdapter extends PagerAdapter {

    public int getCount() {
        return 2;
    }

    public Object instantiateItem(View collection, int position) {
        LayoutInflater inflater = (LayoutInflater) collection.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        int resId = 0;
        switch (position) {
        case 0:
            resId = R.layout.italiclc;

            break;
        case 1:
            resId = R.layout.italicuc;
            break;
        }

        View view = inflater.inflate(resId, null);
        if (resId == R.layout.italiclc) {
            TextView italiclowercase = (TextView) view
                    .findViewById(R.id.italiclowercase);
            italiclowercase.setTypeface(calligraphyfont);
        }
        if (resId == R.layout.italicuc) {
            TextView italicuppercase = (TextView) view
                    .findViewById(R.id.italicuppercase);
            italicuppercase.setTypeface(calligraphyfont);

        }
        ((ViewPager) collection).addView(view, 0);

        return view;
    }

    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((View) arg2);

    }

    @Override
    public void finishUpdate(View arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == ((View) arg1);

    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public Parcelable saveState() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void startUpdate(View arg0) {
        // TODO Auto-generated method stub

    }

    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

}

}

As I said before, I tried many different ways to get it to work to no avail. The exception is coming from the line that sets the image adapter to the grid view (line 29). Any help that could be provided would be greatly appreciated.

  • 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-06T01:22:15+00:00Added an answer on June 6, 2026 at 1:22 am

    I have the two separate layouts for the two pages, and the first one has the gridview.

    So you have problem in following statement:

    GridView gridview = (GridView) findViewById(R.id.italiclcgrid);
    

    Here you are trying to reference GridView from main.xml. Rather you should reference it from layout file where you have defined it.

    Your code is like this:

    setContentView(R.layout.calligraphyfonts2);
    GridView gridview = (GridView) findViewById(R.id.italiclcgrid);
    

    So you make sure your GridView is defined in calligraphyfonts2 layout or try to refernce it from another layout using inflator.

    If you have defined GridView in italiclc layout then add following changes in code:

    settingspic.setOnClickListener(this);
    backhomebutton.setOnClickListener(this);
    GridView gridview = (GridView) findViewById(R.id.italiclcgrid); // <- Remove this
    gridview.setAdapter(new ImageAdapter(this)); // <-- Remove this
    

    And add it here:

    if (resId == R.layout.italiclc) {
      GridView gridview = (GridView) view.findViewById(R.id.italiclcgrid);
      gridview.setAdapter(new ImageAdapter(mContext));
    
      TextView italiclowercase = (TextView) view.findViewById(R.id.italiclowercase);
      italiclowercase.setTypeface(calligraphyfont);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our group is somewhat new to JVM based development. We are developing applications that
I am somewhat new to android development, this is my first time trying to
I am somewhat new to android and I am setting up my view perspectives
New to Android development and have decided to use NetBeans 6.9.1 as my IDE.
So, my question is somewhat similar to these two questions: Custom View onDraw is
Somewhat new to android, need some help with services. I have a service which
I am somewhat new to Android and have been struggling for hours on how
Somewhat new to .NET 4.0 C# development and have a quick question. I am
I am somewhat new to LINQ and have a quick question regarding deleting. Say,
I am somewhat new to R, and i have this piece of code which

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.