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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:07:42+00:00 2026-05-25T23:07:42+00:00

What I’ve Done I have created a GridView in my layout. This GridView I’d

  • 0

What I’ve Done


I have created a GridView in my layout. This GridView I’d like to fill over my ImageAdapter I’ve created of the Google Documentations: Hello GridView

The picturepath to my pictures, did i save into my datbase and I’d like to fill it over it. Because in my Datbase everything is a String I wrote in my Activity a short function which changes the String[] into a Int[], but I can’t acces that over my ImageAdapter. Afterwards I applied the changes that Mrs. Nikita told me. Also I changed to lil thing to change the String[] to an int[] (is working now).

Question


What do I need to change to get the Int[] to my ImageAdapter that it imports my pictures and that they are shown in the GrindView.
Now I have a Nullpointer Exception at:

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

The Code:


This is the Code of my SmileyConfigActivity.java:

package de.retowaelchli.filterit;

import de.retowaelchli.filterit.database.SmileyDBAdapter;
import de.retowaelchli.filterit.stats.ImageAdapter;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.GridView;


public class SFilterConfigActivity extends Activity {

    //Variablen deklarieren
    private String name;
    private String keyword;
    private Integer[] info;
    private SmileyDBAdapter SmileyHelper;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sfilter_config);

      SmileyHelper = new SmileyDBAdapter(this);

      getImages();

    }


public Integer[] getImages(){



    SmileyHelper.open();

    Cursor c = SmileyHelper.getAllSmileys();
    startManagingCursor(c);

    String[] picture = new String[] { SmileyDBAdapter.INFO };

    int i;
    for (i=0;i< picture.length-1;i++) {
        info[i]=Integer.parseInt(picture[i+1]);

    }

    SmileyHelper.close();

    //Hier wird die Grindview gefüllt
    GridView gridview = (GridView) findViewById(R.id.SmileyGrind);
    gridview.setAdapter(new ImageAdapter(this, info));

    return info;

}



public void onClickSConfigSave(View v){

    EditText edtTextName = (EditText)findViewById(R.id.SFConfigName);
    EditText edtTextKeyword = (EditText)findViewById(R.id.SFConfigKeyword);

    name = edtTextName.getText().toString();
    keyword = edtTextKeyword.getText().toString();

    final Intent i = new Intent(this, SmileyActivity.class);
    startActivity(i);
    }
}

This is the Code of my ImageAdapter.java:

    package de.retowaelchli.filterit.stats;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;


import de.retowaelchli.filterit.SFilterConfigActivity;

public class ImageAdapter extends BaseAdapter {

    private Context mContext;

    public ImageAdapter(Context c, Integer[] imageIds) {
        mContext = c;
        mThumbIds = imageIds;
    }

    //This Guy down here is giving me the NullpointerExcpetion now
    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;
}

And this is how i store the pictures to the Datbase (I only save to place where they are located):

    int drawableID = context.getResources().getIdentifier("angel", "drawable", getPackageName());
    iv.setImageResource(drawableID);

    String info = String.valueOf(drawableID);

    mDbHelper.open();

    mDbHelper.createSmiley("You have received a heavenly message", info);
    mDbHelper.close();

This is the Error-Log I get:

10-04 13:26:25.776: ERROR/AndroidRuntime(10099): FATAL EXCEPTION: main
10-04 13:26:25.776: ERROR/AndroidRuntime(10099): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.retowaelchli.filterit/de.retowaelchli.filterit.SFilterConfigActivity}: java.lang.NullPointerException
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.os.Looper.loop(Looper.java:143)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.app.ActivityThread.main(ActivityThread.java:4196)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at java.lang.reflect.Method.invokeNative(Native Method)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at java.lang.reflect.Method.invoke(Method.java:507)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at dalvik.system.NativeStart.main(Native Method)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099): Caused by: java.lang.NullPointerException
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at de.retowaelchli.filterit.stats.ImageAdapter.getCount(ImageAdapter.java:25)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.widget.GridView.setAdapter(GridView.java:131)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at de.retowaelchli.filterit.SFilterConfigActivity.getImages(SFilterConfigActivity.java:54)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at de.retowaelchli.filterit.SFilterConfigActivity.onCreate(SFilterConfigActivity.java:30)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
10-04 13:26:25.776: ERROR/AndroidRuntime(10099):     ... 11 more

Thx for your help!

  • 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-25T23:07:43+00:00Added an answer on May 25, 2026 at 11:07 pm

    There seems to be a lot of pertinent info missing here but if you fill in the blanks I will update the answer. First problem is what are you retrieving in your getAllSmileys function?

    What you need to understand is that a cursor is like a memory table of results. So you need to tell the cursor which record to fetch from by using move commands otherwise it is uniniitilaized. So assuming your smilleys are stored in the SmileyDBAdapter.INFO column then you can retrieve them like this:

    SmileyHelper.open();
    
    Cursor c = SmileyHelper.getAllSmileys();
    
    if(c!=null)
    {
       int i=0;
       info = new int[c.getCount()]();
    
       //get the column index
       int infoIndex = c.getColumnIndex(SmileyDBAdapter.INFO);
    
       while(c.moveToNext()){
           String infoItem = c.getString(infoIndex );
           int infoItemInteger = Integer.parseInt(infoItem);
           info[i++] =infoItemInteger;
       }
    }
    
    c.close();
    
    SmileyHelper.close();
    

    You are storing the image id’s in the database as string which is making things more complicated. There is no need to parse and valueOf the drawable resource ID’s into and out of a text column in the database. Simply change the column type to integer and always work with integers for your images.

    You can simply use Cursor.getInt() to retrieve the values.

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace

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.