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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:04:27+00:00 2026-05-16T05:04:27+00:00

package one.two; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.SimpleCursorAdapter;

  • 0
package one.two;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;


public class Booking extends Activity
{
    private DBAdapter db; 
    private Spinner colourSpinner;
    public Cursor c;
    public TextView txtArrival;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        db = new DBAdapter(this);
        this.setContentView(R.layout.booking);
        db.open();
        fillData();
        db.close();

        Spinner colourSpinner = (Spinner) findViewById(R.id.myspinner);
    }

    private void fillData()
    {
        Cursor c = db.getSpinnerData();
        startManagingCursor(c);
        String[] from = new String[]{DBAdapter.KEY_ARRIVAL};
        int[] to = new int[]{android.R.id.text1};
        SimpleCursorAdapter adapter =
        new SimpleCursorAdapter(this,R.layout.booking, c, from, to );
        adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
        Spinner colourSpinner = (Spinner) findViewById(R.id.myspinner);
        colourSpinner.setAdapter(adapter);
    }
    public class MyOnItemSelectedListener implements OnItemSelectedListener
    {
        public void onItemSelected(AdapterView<?> arg0, View v,int position, long id)
        {
            if (Booking.this.c.moveToPosition(position)) {
                String title=Booking.this.c.getString(1);
                Booking.this.txtArrival.setText(title);
            }

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

        }
    };
}

Error log

 08-06 01:27:34.874: ERROR/AndroidRuntime(721): Uncaught handler: thread main exiting due to uncaught exception
08-06 01:27:34.893: ERROR/AndroidRuntime(721): java.lang.NullPointerException
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at one.two.Booking$MyOnItemSelectedListener.onItemSelected(Booking.java:53)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:856)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at android.widget.AdapterView.access$200(AdapterView.java:41)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:827)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at android.os.Handler.handleCallback(Handler.java:587)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at android.os.Looper.loop(Looper.java:123)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at android.app.ActivityThread.main(ActivityThread.java:3948)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at java.lang.reflect.Method.invokeNative(Native Method)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at java.lang.reflect.Method.invoke(Method.java:521)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-06 01:27:34.893: ERROR/AndroidRuntime(721):     at dalvik.system.NativeStart.main(Native Method)

Thank you.

  • 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-16T05:04:28+00:00Added an answer on May 16, 2026 at 5:04 am

    In the method fillData() you are creating a local Cursor object “Cursor c”, which hides your class member “public Cursor c”. You are initializing the local variable and when onItemSelected is called Booking.this.c will be null which gives you the NullPointerException.

    Removing the “Cursor” part in fillData() should avoid this.

    private void fillData()
    {
       c = db.getSpinnerData();
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer OK so I made it through my upgrade (yay!) and… May 16, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer I think the error comes from YouTube , see my… May 16, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer You have the Closure Loop Problem. You appear to be… May 16, 2026 at 11:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Booking.java package one.two; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.SimpleCursorAdapter; import
here is my Arrival.java package one.two; import java.io.IOException; import java.util.ArrayList; import java.util.List; import android.app.ListActivity;
Here is my Arrival.java package one.two; import java.io.IOException; import java.util.ArrayList; import java.util.List; import android.app.ListActivity;
How would i make what i selected in the spinner appear in a textview
I'm doing Major Project on my final year and I'm very new to Android
Could someone maybe tell me what i'm doing wrong? I'm betting im missing one
Could someone maybe tell me what i'm doing wrong? I'm betting im missing one
Suppose we have a package called com.example1 containing a Hello class (along with other
i have a table with two columns and two records as follows. TypeOfReport Links
I'm currently writing my bachelor thesis and my university wants a one sided print.

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.