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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:36:14+00:00 2026-05-29T10:36:14+00:00

I’m trying to use an SQLite database to store some data for my app.

  • 0

I’m trying to use an SQLite database to store some data for my app. I’ve got this in my DbHelper class (which extends SqLiteOpenHelper)

// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
        + jarsTable + "( "+colID+" integer primary key autoincrement, "+colName+" varchar(100), " +
        colGoal+" real not null, "+colBal+" real not null, "+colCurr+" varchar(100));";

public DbHelper(Context context) {
    super(context, dbName, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
}

And I’ve got this inside my DataSource class

private Jar cursorToJar(Cursor cursor) {
    Jar myJar = new Jar();
    myJar.setId(cursor.getLong(0));
    myJar.setName(cursor.getString(1));
    myJar.setBalance(cursor.getDouble(2));
    myJar.setGoal(cursor.getDouble(3));
    myJar.setCurrency(cursor.getString(4));
    return myJar;
}

And I get the error I mentioned in the question title, which crashes the app, when it reaches the line myJar.setName above. I’m really a bit confused as to where I’ve gone wrong, I’m getting a string, and my table is storing a field at column 1, I think, so.. yeah. Thanks for the help, in advance

EDIT: Here’s my population method:

public Jar createJar(String name, double goal, String currency) {
    ContentValues values = new ContentValues();
    values.put(DbHelper.colName, name);
    values.put(DbHelper.colGoal, goal);
    values.put(DbHelper.colCurr, currency);
    values.put(DbHelper.colBal, 0.0);
    long insertId = database.insert(DbHelper.jarsTable, null,
            values);
    Log.d("Insert ID:", ""+insertId);
    // To show how to query
    Cursor cursor = database.query(DbHelper.jarsTable,
            allColumns, DbHelper.colID + " = " + insertId, null,
            null, null, null);
    cursor.moveToFirst();
    return cursorToJar(cursor);
}
  • 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-29T10:36:14+00:00Added an answer on May 29, 2026 at 10:36 am

    Always use the cursor’s getColumnIndex() method to access columns. Like so:

    myJar.setName(cursor.getString(cursor.getColumnIndex(colName)));
    

    Not saying that’s absolutely the issue — since you haven’t shown how the Cursor was populated — but it’s likely.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.