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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:03:34+00:00 2026-06-05T17:03:34+00:00

I have a spinner witch is populated from database, when I select an item

  • 0

I have a spinner witch is populated from database, when I select an item ,i would like to return the row id (the primary key) of this item in the database;
this is my code:

private int getcategoryrowid(Spinner spinner){                  

        AndroidOpenDbHelper openHelperClass = new AndroidOpenDbHelper(this);

        // Then we need to get a readable database
        SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();


        //
        Cursor cursor1 = (Cursor) (spinner.getSelectedItem());
        String t=String.valueOf(spinner.getSelectedItem());
        System.out.println(t);
        int rowid = cursor1.getInt(cursor1.getColumnIndex("_id"));
        System.out.println(rowid);
         cursor1.close();
         sqliteDatabase.close();
        return rowid;

}

and this the logcat:

06-14 16:02:01.840: W/dalvikvm(14081): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-14 16:02:01.880: E/AndroidRuntime(14081): FATAL EXCEPTION: main
06-14 16:02:01.880: E/AndroidRuntime(14081): java.lang.ClassCastException: java.lang.String
06-14 16:02:01.880: E/AndroidRuntime(14081):    at com.app.pfe.Addfile.getcategoryrowid(Addfile.java:345)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at com.app.pfe.Addfile.onClick(Addfile.java:85)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at android.view.View.performClick(View.java:2485)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at android.view.View$PerformClick.run(View.java:9080)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at android.os.Handler.handleCallback(Handler.java:587)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at android.os.Looper.loop(Looper.java:123)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at android.app.ActivityThread.main(ActivityThread.java:3683)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at java.lang.reflect.Method.invokeNative(Native Method)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at java.lang.reflect.Method.invoke(Method.java:507)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-14 16:02:01.880: E/AndroidRuntime(14081):    at dalvik.system.NativeStart.main(Native Method)

what is wrong in my code ?

  • 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-05T17:03:36+00:00Added an answer on June 5, 2026 at 5:03 pm

    Why have a whole separate class? You can get it from the onItemSelected method, since it gives it to you in the parameters coming in (it’s the long id part)…

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                long rowId = id;    
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spinner with a custom adapter displaying objects from a database. When
I have a listview which loads its data from sqlite database. Each row in
I'm developing an Android application with a spinner. I have this problem: This is
In main.xml I would like to have a spinner1 with two radio buttons and
I have used spinner in my project but it looks like But i want
I have an android spinner that's populated by a list of strings using an
I have an application, which has a Spinner that I want populated with some
I have a AS spinner class that I downloaded from Jake Hawkes ( click
I'm using the ActionBar. I'd like to have a refresh progress spinner on the
I have a Spinner Control bind with data from Sqllite during the Page Load

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.