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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:38:53+00:00 2026-05-22T02:38:53+00:00

i got no idea why it return me nullpointerexception. I think is because the

  • 0

i got no idea why it return me nullpointerexception. I think is because the table don’t have data. So, the data seem like did not add into database

this is my activity class.

private void createdata(){

    String title[] = {"rancangan1", "rancangan2", "rancangan3", "rancangan4", "rancangan5"};
    String date[] = {"isnin", "selasa", "rabu", "khamis", "jumaat"};
    String time[] = {"17:00-18:00", "18:00-19:00", "17:00-18:00", "18:00-19:00", "19:00-20:00"};
    String channel[] = {"astro ria", "astro ria", "astro ria", "astro ria", "astro ria"};
    try{
    for(int i = 0; i < title.length; i++){
        ContentValues values = new ContentValues();
        values.put(ImamShareData.DataContent.KEY_PROGRAM_TITLE, title[i]);
        values.put(ImamShareData.DataContent.KEY_PROGRAM_DATE, date[i]);
        values.put(ImamShareData.DataContent.KEY_PROGRAM_TIME, time[i]);
        values.put(ImamShareData.DataContent.KEY_PROGRAM_CHANNEL, channel[i]);
        cr.insert(ImamShareData.DataContent.PROGRAM_URI, values);
            //Log.i(TAG, "Successfully added index " + i + " as ID " + mId[i]);
    }
    }catch(Exception e){
        Log.v("error",""+e);
    }

}
private void filldata(){

    String[] from = new String[]{ImamShareData.DataContent.KEY_PROGRAM_DATE, ImamShareData.DataContent.KEY_PROGRAM_TIME, ImamShareData.DataContent.KEY_PROGRAM_CHANNEL};
    String[] from1 = new String[]{ImamShareData.DataContent.KEY_PROGRAM_TITLE};

    int[] to = new int[]{R.id.programdate, R.id.programtime, R.id.programchannel};
    int[] to1 = new int[]{R.id.programtitle};

    SimpleExpandableListAdapter SEL = new SimpleExpandableListAdapter(this, 
                    createGroupList(), R.layout.programgroup_row, from1, to1,       
                    createChildList(), R.layout.programchild_row, from, to);
    setListAdapter( SEL );
}
private List createGroupList() {
    String[] column = new String[]{ImamShareData.DataContent.KEY_PROGRAM_TITLE};
    ArrayList result = new ArrayList();
    String title[] = null;
    for( int i = 1 ; i <= 5; ++i ) { 
        Cursor cursor = managedQuery(ImamShareData.DataContent.PROGRAM_URI, column, null, null, null);    
        HashMap m = new HashMap();
        title[i] = cursor.getColumnName(cursor.getColumnIndex(ImamShareData.DataContent.KEY_PROGRAM_TITLE));
        m.put(ImamShareData.DataContent.KEY_PROGRAM_TITLE, title[i]); 
        result.add( m );
    } 
    return result;
}

private List createChildList() {
    String date;
    String time;
    String channel;
    String[] column = new String[]{ImamShareData.DataContent.KEY_PROGRAM_DATE, ImamShareData.DataContent.KEY_PROGRAM_TIME, ImamShareData.DataContent.KEY_PROGRAM_CHANNEL};
    ArrayList result = new ArrayList();
    for( int i = 1 ; i <= 5 ; ++i ) {
        ArrayList secList = new ArrayList();
        for( int n = 0 ; n < 3 ; n+=3 ) {
            Cursor cursor = managedQuery(ImamShareData.DataContent.PROGRAM_URI, column, null, null, null);
            HashMap child = new HashMap();
            date = cursor.getColumnName(cursor.getColumnIndex(ImamShareData.DataContent.KEY_PROGRAM_DATE));
            time = cursor.getColumnName(cursor.getColumnIndex(ImamShareData.DataContent.KEY_PROGRAM_TIME));
            channel = cursor.getColumnName(cursor.getColumnIndex(ImamShareData.DataContent.KEY_PROGRAM_CHANNEL));
            child.put(ImamShareData.DataContent.KEY_PROGRAM_DATE, date);
            child.put(ImamShareData.DataContent.KEY_PROGRAM_TIME, time);
            child.put(ImamShareData.DataContent.KEY_PROGRAM_CHANNEL, channel);
            secList.add( child );
        }
        result.add( secList );
    }
    return result;
}

this is my contentprovider class

@Override
public Uri insert(Uri uri, ContentValues initialvalues) {
    TableNumber = sUriMatcher.match(uri);
    if( TableNumber != PROGRAM){
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    ContentValues values;
    if(initialvalues != null){
        values = new ContentValues(initialvalues);
    }else{
        values = new ContentValues();
    }

    SQLiteDatabase mDb = mDbHelper.getWritableDatabase();
    long rowId = mDb.insert(DatabaseHelper.TABLE_PROGRAM, null, values);
    if(rowId > 0){
        Uri programUri = ContentUris.withAppendedId(ImamShareData.DataContent.PROGRAM_URI, rowId);
        getContext().getContentResolver().notifyChange(programUri, null);
        return programUri;
    }
    throw new IllegalArgumentException("Failed to insert row into " + uri);
}

this is my datasharing class

public static final class DataContent implements BaseColumns{   

    public static final Uri PROGRAM_URI = Uri.parse("content://" + AUTHORITY + "/" + PROGRAMPATH);

    public static final String CONTENT_MORE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.android.imammuda";
    public static final String CONTENT_ONE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.android.imammuda";

    public static final String KEY_PROGRAM_ID = "_id";
    public static final String KEY_PROGRAM_TITLE = "ProgramTitle";
    public static final String KEY_PROGRAM_DATE = "ProgramDate";
    public static final String KEY_PROGRAM_TIME = "ProgramTime";
    public static final String KEY_PROGRAM_CHANNEL = "ProgramChannel";
}

this is my logcat

05-12 16:05:46.024: ERROR/AndroidRuntime(5175): Caused by: java.lang.NullPointerException
05-12 16:05:46.024: ERROR/AndroidRuntime(5175):     at com.android.imammuda.Program.createGroupList(Program.java:112)
05-12 16:05:46.024: ERROR/AndroidRuntime(5175):     at com.android.imammuda.Program.filldata(Program.java:82)
  • 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-22T02:38:53+00:00Added an answer on May 22, 2026 at 2:38 am

    You have not initialized your title variable in method createGroupList:

     String title[] = null;
    

    …

    title[i] = cursor.getColumnName....
    

    in the for loop the length is hard coded to maximum 5, so the easiest fix is:

    String[] title = new String[5];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a return from a server which is a block of html,
How to create a true function pipeline using C#? I got some idea like
So basically I have got an idea and I want to hear your opinions
Anyone got an idea why this doesnt work? Im tyring to add the listener
Anyone got an idea how to get from an Xserver the list of all
I got this idea a long time ago when i saw an app do
Has anybody got an idea of how to create a .Contains(string) function using Linq
Has anyone got any idea why the menu is rendering below the rotating images
I've got a game idea that requires some semi-realistic simulation of a fluid flowing
I just got this question on an interview and had no idea how to

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.