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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:48:19+00:00 2026-06-16T02:48:19+00:00

Basically, I can insert into my database and view all the results using the

  • 0

Basically, I can insert into my database and view all the results using the below method and a SimpleCursorAdapter displaying to a ListView – works totally fine.

// Returns a Cursor containing all JSON strings
public Cursor getAllJSONstrings()
{       
    // Return all JSONstrings ordered by COLUMN_ID
    return ssDatabase.query(TABLE_ROUTINES, new String[] {COLUMN_ROWID, COLUMN_JSON}, null, null, null, null, COLUMN_ROWID);        
}

However, the following method gives nothing less than the NullPointerException every time I query.

The id LogCat tag shows the tag as being what it should be, 1 for the first item etc.

// Return one JSONstring in String form 
public String getJSONstring(long id)
{
    Log.i(TAG, "getJSONstringStart... id=" + id);

    Cursor cursor;

    Log.i(TAG, "Cursor defined");

    /****** NullPointerException LINE ******/
    cursor = ssDatabase.query(TABLE_ROUTINES, null, "_id=" + id, null, null, null, null);

    Log.i(TAG, "Exceed Cursor");

    int index = cursor.getColumnIndex(COLUMN_JSON);

    Log.i(TAG, "index=" + index);

    return cursor.getString(index);
}

For what it’s worth, this method getJSONString(long id) is being executed in an AsyncTask. The id it refers to is the id in an OnItemClickListeners onItemClick method.

Any help would be very appreciated, my head has gone square!

Cheers!

  • 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-16T02:48:21+00:00Added an answer on June 16, 2026 at 2:48 am

    You have to do moveToFirst(). Your method is assuming that the cursor’s current row pointer is already set to the first row and that getString(index) will return the value of COLUMN_JSON for the first row.

    This isn’t true. You should never assume that your query returned something. If the selection clause didn’t return any rows, then cursor.getCount() will return 0. In addition, the query may throw a SQLite exception. Any time you look at the results of a query, you should enclose your code in

    try {

    // query
    if ((cursor != null) && (cursor.getCount() > 0)) {
    
        // some operation
    
    }
    ...
    

    } catch (Exception e) {

    }

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

Sidebar

Related Questions

I have a database and i can insert into it and read from it
Hi All I am havinga problem with Entity framework, basically as you can see
So I have this stored procedure to insert a message into my database. I
I am using a dataset to insert data being converted from an older database.
I need to insert pairs of input values from a form into mysql database.
I'm trying to do a huge bulk insert into an SqlCe database (version 3.5,
Basically: Can my model classes contain @NoBinding annotations with multiple values? If I have
In prototypal languages object can basically clone each other. So, lets say we have
I keep reading that object-oriented programming can basically be done in any programming language,
I want to make a site where there user can basically navigate the web

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.