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

  • Home
  • SEARCH
  • 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 8620767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:39:31+00:00 2026-06-12T06:39:31+00:00

I am trying to populate a spinner from a sqlite database. The database is

  • 0

I am trying to populate a spinner from a sqlite database. The database is +400mb and i manually dropped into /data/data/myapplicationpackage/databases directory in my sdcard.

I also have a ContentProvider to access the data. Here is some relevant part of the code:

private static final String DATABASE_NAME = "mydb.db";
private static final int DATABASE_VERSION = 1;
private static final String DOSIS_PA_TABLE = "mytable";

public static final String KEY_ID_PA = "_id";
public static final String KEY_DESCRIPTION = "description";


public static final String CONTENT_AUTHORITY = "com.mypackage.myappname";
public static final Uri BASE_CONTENT_URI = Uri.parse("content://"
        + CONTENT_AUTHORITY);

private static final String PATH_DOSISPED_PA = "mytable";

public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
        .appendPath(PATH_DOSISPED_PA).build();

public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.myappname.mytable";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.myappname.mytable";

private static final int DOSISPAS = 1;
private static final int DOSISPA_ID = 2;

private static final UriMatcher uriMatcher;
static {
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    uriMatcher.addURI("CONTENT_AUTHORITY", "mytable", DOSISPAS);
    uriMatcher.addURI("CONTENT_AUTHORITY", "mytable/*", DOSISPA_ID);
}

And this is part of the activity where i trigger the query:

contentResolver = getContentResolver();
    Uri uri = MyContentProvider.CONTENT_URI;
    Cursor cursor = contentResolver.query(uri, null, null, null, null);

    // create an array to specify which fields we want to display
    String[] from = new String[] { MyContentProvider.KEY_DESCRIPTION };
    // create an array of the display item we want to bind our data to
    int[] to = new int[] { android.R.id.text1 };
    // create simple cursor adapter
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            android.R.layout.simple_spinner_item, cursor, from, to);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // get reference to our spinner
    Spinner spinner = (Spinner) findViewById(R.id.spinner_pas);
    spinner.setAdapter(adapter);//THIS IS WHERE THE EXCEPTION IS THRWON

And a NullPointerException is thrown at this line of code:

    spinner.setAdapter(adapter);

And here is the logcat:

10-02 18:41:32.109: E/AndroidRuntime(2783): FATAL EXCEPTION: main
10-02 18:41:32.109: E/AndroidRuntime(2783): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.edoctores.android.apps.idoctus/com.edoctores.android.apps.idoctus.ui.PediatricDosisActivity}: java.lang.NullPointerException
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.os.Looper.loop(Looper.java:137)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at java.lang.reflect.Method.invokeNative(Native Method)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at java.lang.reflect.Method.invoke(Method.java:511)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at dalvik.system.NativeStart.main(Native Method)
10-02 18:41:32.109: E/AndroidRuntime(2783): Caused by: java.lang.NullPointerException
10-02 18:41:32.109: E/AndroidRuntime(2783):     at com.edoctores.android.apps.idoctus.ui.PediatricDosisActivity.onCreate(PediatricDosisActivity.java:72)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.Activity.performCreate(Activity.java:5008)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-02 18:41:32.109: E/AndroidRuntime(2783):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-02 18:41:32.109: E/AndroidRuntime(2783):     ... 11 more

I have been the whole day trying to fix it without any luck. Could someone help me and point me into the right direction? Thanks a lot in advance

  • 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-12T06:39:32+00:00Added an answer on June 12, 2026 at 6:39 am

    findViewById() only returns a View if it is currently shown otherwise it returns null. You must have a Spinner with the id spinner_pas in the layout that you passed to setContentView() (or in a layout that has otherwise already been inflated).

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

Sidebar

Related Questions

I'm trying to populate a drop down list with data from an SQL database
I'm trying to populate a directory from the contents of a bundle built into
I'm trying to populate listview from my SQLite database... this is how I get
I have a spinner and I am trying to populate it manually in the
I'm trying to populate this list with strings from the object data. It comes
Im trying to populate a JSF Datatable with data that I am retrieving from
I am trying to populate a collection with data from a JSON file. I'm
So im trying to populate an auto-complete search form from my database. Here is
I am trying to populate a spinner, but am getting an error. Here is
I am trying to populate the list li from the LoginAction on to the

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.