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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:10:47+00:00 2026-06-11T19:10:47+00:00

I use my cursor to get a certain value out of my database table.

  • 0

I use my cursor to get a certain value out of my database table. It gets it out of a column with the type ‘TEXT’. The idea is that the standard value of the column is blank, but when a certain button is clicked, a query will add “true” to it.

String var = c.getString(1); //use cursor to get value

But when I want to use this to compare to a string, f.e.

if(var.equals("true")) {
//do something crazy
}

I get an error on items where there is nothing filled in the DB. Only the fields where actually “true” is filled in won’t give an error. I tried c.getString(1).toString(); but this doesn’t do the trick… any ideas?

  • 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-11T19:10:48+00:00Added an answer on June 11, 2026 at 7:10 pm

    check should be like below

    if("true".equals(var)) {
    

    So that you will not get NullPointerException

    As suggested in Cursor#getString Javadoc

    The result and whether this method throws an exception when the column value is null or the column type is not a string type is implementation-defined.

    You should use Cursor#isNull or Cursor#moveToFirst before checking value from database.

     if(!c.isNull(1))
     //Get Value here
    
    Or 
    
    if(c.moveToFirst())
     //get value here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like to use a Singleton as a globally accessible cache for certain database
I'm using a database, and there's a list fragment which use a cursor adapter
In my application I use cursor to get information from SQLite data base like
I am wondering when or if its ok to use a cursor to get
I need the opposite information that the question How to get cursor position on
I'm trying to use pyodbc to return dates that match certain criteria from an
I use a cursor to iterate through quite a big table. For each row
I have a contacts table and I need to get only certain IDs. Imagine
currently I am using ListActivity. I use a cursor to get the data from
Really confused regarding the use of a cursor. I have one activity that works

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.