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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:22:25+00:00 2026-06-04T18:22:25+00:00

On click after making a scroll (Vertical) I am getting null pointer exception instead

  • 0

On click after making a scroll (Vertical) I am getting null pointer exception instead of a TextView.
For your reference I am using following code:

collection_image.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     >
    <GridView
    android:id="@+id/gridView"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:numColumns="3"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:columnWidth="120dp"
    android:gravity="center" />
</RelativeLayout>

adapter_griditem.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:gravity="center" >

   <TextView
       android:id="@+id/grid_item_text"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:gravity="center_horizontal"
       android:textColor="#FFFFFF" />

</LinearLayout>

getView function of ImageAdapter that extends BaseAdapter class

public View getView(int position, View convertView, ViewGroup parent) {
    View MyView = convertView;
    try{
        Image cached = images[position];
        if(convertView == null) {
            MyView = LayoutInflater.from(mContext).inflate(R.layout.adapter_griditem, null);
        }
        title = (TextView)MyView.findViewById(R.id.grid_item_text);

        if(cached.thumb == null) {

            // no cached thumb, 

        } else {
            title.setTag(images[position].fullPath);
            title.setText(imageCollection[position]);
            title.setCompoundDrawablesWithIntrinsicBounds(null, new BitmapDrawable(cached.thumb), null, null);
        }
    }catch (Exception e) {
        e.printStackTrace();
    }
    return MyView;
}

On Activity (Two functions):

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    return inflater.inflate(R.layout.collection_image, container, false);
}

@Override
public void onResume(){
    imageAdapter = new ImageAdapter(getActivity().getApplicationContext(), collectionCount, mTag, imageCollection, mType);

        View fragmentView = getView();    
        mGridView = (GridView) fragmentView.findViewById(R.id.gridView);
        mGridView.destroyDrawingCache();
        mGridView.setAdapter(imageAdapter);

        mGridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                TextView mtext = (TextView) parent.getChildAt(position).findViewById(R.id.grid_item_text); 
                if(mtext != null){
                    String imageURL = (String) mtext.getTag();
                    gridHandler(imageURL);
                }
            }
        });

}

Anyone please??

Edit1:

Logcat===

05-30 18:17:23.371: E/AndroidRuntime(512): FATAL EXCEPTION: main
05-30 18:17:23.371: E/AndroidRuntime(512): java.lang.NullPointerException
05-30 18:17:23.371: E/AndroidRuntime(512):  at com.tftus.greetz.fragments.DisplayCardsFragment$1.onItemClick(DisplayCardsFragment.java:71)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.widget.AdapterView.performItemClick(AdapterView.java:282)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.widget.AbsListView.performItemClick(AbsListView.java:1032)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2447)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.widget.AbsListView$1.run(AbsListView.java:3065)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.os.Handler.handleCallback(Handler.java:587)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.os.Looper.loop(Looper.java:126)
05-30 18:17:23.371: E/AndroidRuntime(512):  at android.app.ActivityThread.main(ActivityThread.java:3997)
05-30 18:17:23.371: E/AndroidRuntime(512):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 18:17:23.371: E/AndroidRuntime(512):  at java.lang.reflect.Method.invoke(Method.java:491)
05-30 18:17:23.371: E/AndroidRuntime(512):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-30 18:17:23.371: E/AndroidRuntime(512):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-30 18:17:23.371: E/AndroidRuntime(512):  at dalvik.system.NativeStart.main(Native Method)

code of “DisplayCardsFragment.java:71”

TextView mtext = (TextView) parent.getChildAt(position).findViewById(R.id.grid_item_text);

  • 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-04T18:22:27+00:00Added an answer on June 4, 2026 at 6:22 pm

    i think its not get refrences for xml file so null pointer exception

    TextView mtext = (TextView)v.findViewById(R.id.grid_item_text); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with making my button perform a click after a postback.
I'm using jQuery BlockUI Plugin and I'd like to do Javascript:history back(); after Click
After making an auto complete text view once the user click the OK button(which
I try to start an action after click on the button in my alterView
I have simple html code that plays YouTube video after click on the image:
I'm trying to add a $('body').live('click') listener after the user clicks on a div.
$().ready(function(){ $(#move-to).click(function(){ $(body).bind(click,function(){ alert(foo); }); }); }); Why I see alert(foo) immediately after click
I try to play jpg (in loop), after click mp4 should be played after
I'm creating a Tic tac toe game, in that after click made by user
i'm making a workbook creator in C#.net ( using visual studio ) the book

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.