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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:38:23+00:00 2026-06-10T12:38:23+00:00

Helllo people I’ve got NullPointerException in LogCat. When I opened my application, I get

  • 0

Helllo people I’ve got NullPointerException in LogCat. When I opened my application, I get force close. Plus, in the LogCat says that Caused by NullPointerException at main.page getAllNames(). So I thought it’s something to do with my getAllNames() method in my database file.

My codes are below:
TestSpinnerDB.java

@Override
    public void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.spinner_test);

        Spinner testSpinner = (Spinner) findViewById(R.id.nameSpinner);
        Cursor testCursor = friendDB.getAllNames();
        startManagingCursor(testCursor);

        String[] from = new String[]{BuddyDBAdapter.KEY_NAME};
        int[] to = new int[]{android.R.id.text1};
        SimpleCursorAdapter testAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, testCursor, from, to);
        testAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        testSpinner.setAdapter(testAdapter);

        testSpinner.setOnItemSelectedListener(new OnItemSelectedListener()
            {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
                {
                    Cursor c = (Cursor)parent.getItemAtPosition(pos);
                    testSpinnerId = c.getInt(c.getColumnIndexOrThrow(BuddyDBAdapter.KEY_ROWID));

                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0)
                {
                    // TODO Auto-generated method stub

                }
            });

    }

BuddyDBAdapter.java

public class BuddyDBAdapter extends AnniversaryDBAdapter
{
    public static final String KEY_ROWID = "name_id";
    public static final String KEY_NAME = "name";
    private static final String TAG = "DBAdapter";
    private static final String CREATE_TABLE_BUDDIESLIST = "buddiesList";

    public BuddyDBAdapter(Context ctx)
    {
        super(ctx);
    }

    public long insertNames(String name)
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_NAME, name);
        return db.insert(CREATE_TABLE_BUDDIESLIST, null, initialValues);
    }

    public boolean deleteName(long rowId)
    {
        return db.delete(CREATE_TABLE_BUDDIESLIST, KEY_ROWID + "=" + rowId, null) > 0;
    }

    public Cursor getAllNames()
    {
        return db.query(CREATE_TABLE_BUDDIESLIST, new String[] { KEY_ROWID, KEY_NAME }, null, null, null, null, null);
    }

    public Cursor getName(long rowId) throws SQLException
    {
        Cursor c = db.query(true, CREATE_TABLE_BUDDIESLIST, new String[] { KEY_ROWID, KEY_NAME }, KEY_ROWID + "=" + rowId, null, null, null, null, null);
        if(c != null)
        {
            c.moveToFirst();
        }
        return c;
    }
}

This is my LogCat

08-30 15:03:53.361: I/dalvikvm(715): threadid=3: reacting to signal 3
08-30 15:03:53.381: I/dalvikvm(715): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:03:53.781: D/gralloc_goldfish(715): Emulator without GPU emulation detected.
08-30 15:03:53.871: I/dalvikvm(715): threadid=3: reacting to signal 3
08-30 15:03:53.881: I/dalvikvm(715): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:04:06.101: D/AndroidRuntime(715): Shutting down VM
08-30 15:04:06.101: W/dalvikvm(715): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-30 15:04:06.121: E/AndroidRuntime(715): FATAL EXCEPTION: main
08-30 15:04:06.121: E/AndroidRuntime(715): java.lang.RuntimeException: Unable to start activity ComponentInfo{main.page/main.page.TestSpinnerDB}: java.lang.NullPointerException
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.os.Looper.loop(Looper.java:137)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-30 15:04:06.121: E/AndroidRuntime(715):  at java.lang.reflect.Method.invokeNative(Native Method)
08-30 15:04:06.121: E/AndroidRuntime(715):  at java.lang.reflect.Method.invoke(Method.java:511)
08-30 15:04:06.121: E/AndroidRuntime(715):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-30 15:04:06.121: E/AndroidRuntime(715):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-30 15:04:06.121: E/AndroidRuntime(715):  at dalvik.system.NativeStart.main(Native Method)
08-30 15:04:06.121: E/AndroidRuntime(715): Caused by: java.lang.NullPointerException
08-30 15:04:06.121: E/AndroidRuntime(715):  at main.page.BuddyDBAdapter.getAllNames(BuddyDBAdapter.java:35)
08-30 15:04:06.121: E/AndroidRuntime(715):  at main.page.TestSpinnerDB.onCreate(TestSpinnerDB.java:32)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.Activity.performCreate(Activity.java:4465)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-30 15:04:06.121: E/AndroidRuntime(715):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-30 15:04:06.121: E/AndroidRuntime(715):  ... 11 more
08-30 15:04:06.481: I/dalvikvm(715): threadid=3: reacting to signal 3
08-30 15:04:06.501: I/dalvikvm(715): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:04:06.661: I/dalvikvm(715): threadid=3: reacting to signal 3
08-30 15:04:06.681: I/dalvikvm(715): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:04:10.601: I/dalvikvm(739): threadid=3: reacting to signal 3
08-30 15:04:10.621: I/dalvikvm(739): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:04:11.011: D/gralloc_goldfish(739): Emulator without GPU emulation detected.
08-30 15:04:11.111: I/dalvikvm(739): threadid=3: reacting to signal 3
08-30 15:04:11.131: I/dalvikvm(739): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:05:10.671: D/AndroidRuntime(739): Shutting down VM
08-30 15:05:10.671: W/dalvikvm(739): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-30 15:05:10.711: E/AndroidRuntime(739): FATAL EXCEPTION: main
08-30 15:05:10.711: E/AndroidRuntime(739): java.lang.RuntimeException: Unable to start activity ComponentInfo{main.page/main.page.TestSpinnerDB}: java.lang.NullPointerException
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.os.Looper.loop(Looper.java:137)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-30 15:05:10.711: E/AndroidRuntime(739):  at java.lang.reflect.Method.invokeNative(Native Method)
08-30 15:05:10.711: E/AndroidRuntime(739):  at java.lang.reflect.Method.invoke(Method.java:511)
08-30 15:05:10.711: E/AndroidRuntime(739):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-30 15:05:10.711: E/AndroidRuntime(739):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-30 15:05:10.711: E/AndroidRuntime(739):  at dalvik.system.NativeStart.main(Native Method)
08-30 15:05:10.711: E/AndroidRuntime(739): Caused by: java.lang.NullPointerException
08-30 15:05:10.711: E/AndroidRuntime(739):  at main.page.BuddyDBAdapter.getAllNames(BuddyDBAdapter.java:35)
08-30 15:05:10.711: E/AndroidRuntime(739):  at main.page.TestSpinnerDB.onCreate(TestSpinnerDB.java:32)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.Activity.performCreate(Activity.java:4465)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-30 15:05:10.711: E/AndroidRuntime(739):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-30 15:05:10.711: E/AndroidRuntime(739):  ... 11 more
08-30 15:05:10.881: I/dalvikvm(739): threadid=3: reacting to signal 3
08-30 15:05:10.891: I/dalvikvm(739): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:05:11.301: I/dalvikvm(739): threadid=3: reacting to signal 3
08-30 15:05:11.311: I/dalvikvm(739): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:10:10.791: I/Process(739): Sending signal. PID: 739 SIG: 9
08-30 15:34:24.541: I/dalvikvm(1844): threadid=3: reacting to signal 3
08-30 15:34:24.581: I/dalvikvm(1844): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:34:24.861: D/gralloc_goldfish(1844): Emulator without GPU emulation detected.
08-30 15:34:28.141: D/AndroidRuntime(1844): Shutting down VM
08-30 15:34:28.141: W/dalvikvm(1844): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-30 15:34:28.161: E/AndroidRuntime(1844): FATAL EXCEPTION: main
08-30 15:34:28.161: E/AndroidRuntime(1844): java.lang.RuntimeException: Unable to start activity ComponentInfo{main.page/main.page.TestSpinnerDB}: java.lang.NullPointerException
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.os.Looper.loop(Looper.java:137)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.ActivityThread.main(ActivityThread.java:4424)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at java.lang.reflect.Method.invokeNative(Native Method)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at java.lang.reflect.Method.invoke(Method.java:511)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at dalvik.system.NativeStart.main(Native Method)
08-30 15:34:28.161: E/AndroidRuntime(1844): Caused by: java.lang.NullPointerException
08-30 15:34:28.161: E/AndroidRuntime(1844):     at main.page.BuddyDBAdapter.getAllNames(BuddyDBAdapter.java:35)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at main.page.TestSpinnerDB.onCreate(TestSpinnerDB.java:32)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.Activity.performCreate(Activity.java:4465)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-30 15:34:28.161: E/AndroidRuntime(1844):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-30 15:34:28.161: E/AndroidRuntime(1844):     ... 11 more
08-30 15:34:28.491: I/dalvikvm(1844): threadid=3: reacting to signal 3
08-30 15:34:28.511: I/dalvikvm(1844): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:34:28.722: I/dalvikvm(1844): threadid=3: reacting to signal 3
08-30 15:34:28.731: I/dalvikvm(1844): Wrote stack traces to '/data/anr/traces.txt'
08-30 15:34:30.381: I/Process(1844): Sending signal. PID: 1844 SIG: 9

Oh by the way, I’ve managed to display data into spinner like weeks ago, but recently after I’ve created tables within one database file, I couldn’t display data into spinner.

I’ve followed this example Android: populate a Spinner from a SQLite database which made me able to display data.

I’ve followed that example again and I’ve received NullPointerException and force close.

Any help will be greatly appreciated. Thanks

UPDATE

I’ve posted the full code of BuddyDBAdapter.java

  • 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-10T12:38:24+00:00Added an answer on June 10, 2026 at 12:38 pm

    The only one possible thing is,

    your db object is null in getAllNames()
    method of BuddyDBAdapter Class…

    TRY:

    public Cursor getAllNames()
    {
      if(db != null)
      return db.query(CREATE_TABLE_BUDDIESLIST, new String[] { KEY_ROWID, KEY_NAME }, null, null, null, null, null);
      return null;
    }
    

    EDIT:

    Also call

    BuddyDBAdapter friendDB = new BuddyDBAdapter(this);
    

    in onCreate() of TestSpinnerDB Activity..

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

Sidebar

Related Questions

I'm one of those people that has to get their code to compile with
Hello stackoverflow people! I've got a problem which I haven't been able to solve
Something that I see people doing all the time is: class Man(object): def say_hi(self):
Hello I have recently uploaded an application to the app store and it got
Hello people I've been struggling to use sqlite in my C#2.0 application and I
Hello people is it true that we cannot integrate Saxon with Visual Studio? Because
Hello good people of Stack Overflow, I am having trouble with an application I
Hello People how can i open userControl and close in the 2 seconds and
Hello kind and patient people of the internet. Note that I have read and
Hello fellow computer people :) I have a shell script that I will use

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.