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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:45:41+00:00 2026-05-28T13:45:41+00:00

Trying to set up a gridview with a custom adapter, I get my cursor

  • 0

Trying to set up a gridview with a custom adapter, I get my cursor and set the adapter in ASyncTask…

Here is my code for it all:

private class getAllData extends AsyncTask<Context, Void, Cursor> {
    protected void onPreExecute () {
        dialog = ProgressDialog.show(Shows.this, "", 
                "Loading shows. Please wait...", true);
    }

    /** The system calls this to perform work in a worker thread and
      * delivers it the parameters given to AsyncTask.execute() */

    @Override
    protected Cursor doInBackground(Context... params) {
        // TODO Auto-generated method stub
        JSONParser.getAllData(params[0]);
        c = mDbHelper.fetchAllShows();
        return c;
    }

    protected void onPostExecute(Cursor c) {
        startManagingCursor(c);

        String[] str = new String[] {ShowsDbAdapter.KEY_SHOW_TITLE};
        int[] to = new int[] {R.id.textView1};

        GridAdapter ga = new GridAdapter(Shows.this, R.layout.icon,c,str,to);
        gridView.setAdapter(ga);
        dialog.dismiss();
    }
}

And here is my Adapter…

public class GridAdapter extends SimpleCursorAdapter {
       private Context context; 
       private int mLayout;
       private Cursor mCursor;

       public GridAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
           super(context, layout, c, from, to);

           this.context = context;

           mLayout = layout;

           this.mCursor = c;


        }



       @Override
       public View newView(Context context, Cursor cursor, ViewGroup parent) {

           Cursor c = getCursor();


           final LayoutInflater inflater = LayoutInflater.from(context);

           View v = inflater.inflate(mLayout, null);


           v.setLayoutParams(new GridView.LayoutParams(150,150));
           int nameCol = c.getColumnIndex("show_title");
           String name = c.getString(nameCol);
           TextView tv = (TextView) v.findViewById(R.id.textView1);

           if (name != null) {
               Log.e("GRIDVIEW", "I'm in here");
               tv.setText(name);
           }

           return v;

       } 


       public void bindView(View v, Context context, Cursor c) {


           int nameCol = c.getColumnIndex("show_title");
           String name = c.getString(nameCol);

           TextView tv = (TextView) v.findViewById(R.id.textView1);
           if (name != null) {
               tv.setText(name);
           }

           ImageView iv = (ImageView) v.findViewById(R.id.album_image);
           iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
           iv.setImageResource(R.drawable.icon);
       }

}

I realize its a little messy and not the best but it should be working… here are my errors:

> 07-05 11:02:32.729: ERROR/AndroidRuntime(5953): FATAL EXCEPTION: main
07-05 11:02:32.729: ERROR/AndroidRuntime(5953): java.lang.NullPointerException
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at com.android.showapp.Shows$getAllData.onPostExecute(Shows.java:112)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at com.android.showapp.Shows$getAllData.onPostExecute(Shows.java:1)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at android.os.AsyncTask.finish(AsyncTask.java:417)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at android.os.Looper.loop(Looper.java:144)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at android.app.ActivityThread.main(ActivityThread.java:4937)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at java.lang.reflect.Method.invokeNative(Native Method)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at java.lang.reflect.Method.invoke(Method.java:521)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-05 11:02:32.729: ERROR/AndroidRuntime(5953):     at dalvik.system.NativeStart.main(Native Method)

R.layout.icon does exist (and it holds the textview and imageview)
  • 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-28T13:45:43+00:00Added an answer on May 28, 2026 at 1:45 pm

    Answer was from Herrmann – no need for a reference to the context and the cursor in my adapter

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

Sidebar

Related Questions

I am trying to set a focus on a dropdown within GridView(gridViewDropDown class) when
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I am using c#.net. Within my Gridview I am trying to set the SelectedRowStyle
When trying to set DoMatchParen I get the following error: E492: Not an editor
Let's say I have a GridViewEx class declared which extends GridView . And inside
I am trying to nest one gridview within another, but I cannot get the
I am trying to display a GridView in a Dialog. Despite all my efforts,
I have been trying to get SqlCacheDependency working. I think I have everything set
I am trying to set the top gridview's column's width to the body's column
I am trying to set the DataTemplate of my ListView.GridView's CellTemplate dynamically at runtime.

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.