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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:33:12+00:00 2026-06-09T18:33:12+00:00

I was watching google 2009 and noticed my code is inefficient and may cause

  • 0

I was watching google 2009 and noticed my code is inefficient and may cause memory issues.

This my implementation

public View getView(final int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            ViewHolder viewHolder;
            if(li == null){
            li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
        if(convertView == null){
            convertView = li.inflate(R.layout.book_case_view, parent, false);

            viewHolder = new ViewHolder();
            viewHolder.image = (ImageView)convertView.findViewById(R.id.bookCover);
            viewHolder.textView = (TextView)convertView.findViewById(R.id.bookLabel);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        bi = dbh.getData(FILES.get(position));

        convertView.setTag(position);
        convertView.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                BookCaseOnClick(position);
            }
        });

        viewHolder.image.setImageResource(R.drawable.book);//Create a drawable backup cover


        viewHolder.textView.setText( bi.getBook_Title());//Object refers to Book_information


viewHolder.textView.setBackgroundResource(R.drawable.alphabet_bar_bg_dark);
//          new LoadCover(image, bi).run();
            LoadCover(viewHolder.image, bi, position);
            return convertView;
        }

static class ViewHolder{
    ImageView image;
    TextView textView;
}

However, I run to an error on this line after first cycle loaded. (second one)

viewHolder = (ViewHolder) convertView.getTag();

These are the errors. The main thing to note down is that an exception was found and passed on the gridview class with a “java.lang.integer” error during debugging

08-16 20:13:02.073: E/AndroidRuntime(6520): FATAL EXCEPTION: main
08-16 20:13:02.073: E/AndroidRuntime(6520): java.lang.ClassCastException: java.lang.Integer
08-16 20:13:02.073: E/AndroidRuntime(6520):     at epub.activity.View_Book_Selection_Screen$BookCaseAdapter.getView(View_Book_Selection_Screen.java:835)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.AbsListView.obtainView(AbsListView.java:1409)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.GridView.makeAndAddView(GridView.java:1222)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.GridView.makeRow(GridView.java:268)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.GridView.fillDown(GridView.java:221)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.GridView.fillFromTop(GridView.java:340)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.GridView.layoutChildren(GridView.java:1136)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.AbsListView.onLayout(AbsListView.java:1260)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1049)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.View.layout(View.java:7175)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.os.Looper.loop(Looper.java:123)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at java.lang.reflect.Method.invokeNative(Native Method)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at java.lang.reflect.Method.invoke(Method.java:507)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-16 20:13:02.073: E/AndroidRuntime(6520):     at dalvik.system.NativeStart.main(Native Method)
  • 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-09T18:33:13+00:00Added an answer on June 9, 2026 at 6:33 pm

    you are setting an integer as tag

    convertView.setTag(position);
    

    but then you are doing

    viewHolder = (ViewHolder) convertView.getTag();
    

    That is the reason you are getting this exception. Either set a viewHolder as tag or while getting convert it to integer

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

Sidebar

Related Questions

I recently watching this video on Google Chrome with great interest. It explains that
Watching some code found on internet I came across this piece of code: int
I just finished watching the Google clean code video on YouTube (see link ,
Google weather API shows temperature in Fahrenheit. After watching this post , I was
I'm watching this Chrome Dev Tools evolution video from Google IO 2012 and then
I'm watching the 2010 Google I/O video on this topic and I have a
I was watching one of Google's app reviews and they were ripping into this
So I was watching a talk by Google's Marissa Mayer about speeding up Google's
I was recently watching a google lecture on mysql and learnt that MySQL wont
After watching the very known video on this topic I decided to go with

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.