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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:39:16+00:00 2026-05-23T15:39:16+00:00

Well i been fighting with this all yesterday and today, i got a simple

  • 0

Well i been fighting with this all yesterday and today, i got a simple SQLite insert that keeps returning a -1 as a return value, i read somewhere to change the primary key name to _id but made no change.

so here are the snaps op the code.
My constants for the fields:

//BALLS TABLE
public  static final String BALLS_TABLE  = "balls";
public  static final String BALL_ID = "id";
public  static final String BALL_USERID = "userId";
public  static final String BALL_MODEL = "model";
public  static final String BALL_BRAND = "brand";
public  static final String BALL_SERIAL = "serial";
public  static final String BALL_NOTES = "notes";
public  static final String BALL_IMAGE = "image";

then on my createTables(SQLiteDatabase db) i got

//BALLS TABLE

db.execSQL(
"create table " + BALLS_TABLE +" (" +
BALL_ID + " integer primary key autoincrement not null," +
BALL_USERID + "integer not null," +
BALL_MODEL + " text not null," +
BALL_BRAND + " text not null," +
BALL_SERIAL + " text not null," +
BALL_NOTES + " text not null," +
BALL_IMAGE + " blob" +
");");

the creation of tables is working as i got other tables that are been populated.

and finally the whole ball Helper class

package com.kegel.android.bowlermanager.data;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class BallHelper {

    private SQLiteDatabase database;
    private ArrayList<Ball> currentBalls;
    private Context context;

    public BallHelper(Context context,SQLiteDatabase database)
    {
        this.context = context;
        this.database = database;
        loadBalls();
    }

    public ArrayList<Ball> getCurrentBalls() {
        return currentBalls;
    }

    public Boolean BallExists(long id)
    {
        for (Ball ball : currentBalls)
        {
            if (ball.getId() == id)
                return true;
        }   
        return false;
    }

    public Boolean BallExists(Ball u)
    {
        for (Ball ball : currentBalls)
        {
            if (ball.getId() == u.getId())
                return true;
        }   
        return false;
    }

    public void updateBall(Ball b) {
        assert(null != b);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] by = null;
        if (b.getImage() != null )
        {
            Bitmap bmp = b.getImage();
            bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);   
            by = baos.toByteArray();  

        }
        ContentValues values = new ContentValues();
        values.put(SQLiteOpenDataHelper.BALL_USERID, 1);
        values.put(SQLiteOpenDataHelper.BALL_MODEL, b.getModel());
        values.put(SQLiteOpenDataHelper.BALL_BRAND , b.getBrand());
        values.put(SQLiteOpenDataHelper.BALL_SERIAL , b.getSerial());
        values.put(SQLiteOpenDataHelper.BALL_NOTES, b.getNotes());
        values.put(SQLiteOpenDataHelper.BALL_IMAGE , by);
        if (b.isValid())
        {
            if (b.getId() == 0)
            {
                b.setId(database.insert(SQLiteOpenDataHelper.BALLS_TABLE, null, values));
            }
            else
            {
                long id = b.getId();
                String where = String.format("%s = %d", SQLiteOpenDataHelper.BALL_ID, id);
                database.update(SQLiteOpenDataHelper.BALLS_TABLE, values, where, null);
            }
            loadBalls();    
        }
    }
    public void deleteBalls(Long id) {
        String where = String.format("%s in (%s)", SQLiteOpenDataHelper.BALL_ID, id);
        database.delete(SQLiteOpenDataHelper.BALLS_TABLE, where, null);
        loadBalls();
    }
    public void deleteBalls(Ball u) {
        String where = String.format("%s in (%s)", SQLiteOpenDataHelper.BALL_ID, u.getId());
        database.delete(SQLiteOpenDataHelper.BALLS_TABLE, where, null);
        loadBalls();
    }
        private void loadBalls() {
        byte[] img = null;
        currentBalls = new ArrayList<Ball>();
        //try
        //{
        Cursor ballsCursor = database.query(SQLiteOpenDataHelper.BALLS_TABLE, new String[] {SQLiteOpenDataHelper.BALL_ID,SQLiteOpenDataHelper.USER_ID, SQLiteOpenDataHelper.BALL_MODEL, SQLiteOpenDataHelper.BALL_BRAND, SQLiteOpenDataHelper.BALL_SERIAL, SQLiteOpenDataHelper.BALL_NOTES, SQLiteOpenDataHelper.BALL_IMAGE}, null, null, null, null, null);
        ballsCursor.moveToFirst();
        Ball b;
        if (! ballsCursor.isAfterLast()) {
            do {
                long id = ballsCursor.getInt(0);
                long bowlerId  = ballsCursor.getLong(1);
                String model = ballsCursor.getString(2);
                String brand = ballsCursor.getString(3);
                String serial = ballsCursor.getString(4);
                String notes = ballsCursor.getString(5);
                img = ballsCursor.getBlob(6);
                Bitmap bmp=BitmapFactory.decodeByteArray(img,0,img.length);
                b = new Ball(context,bowlerId,model,brand,serial,notes);
                b.setId(id);
                b.setImage(bmp);
                currentBalls.add(b);
            } while (ballsCursor.moveToNext());
        }
        ballsCursor.close();
    }
}

A second pair of eyes here will come handy! so if anyone can spot anything here, or let me know if I’m missing something i will really appreciate it. I already checked the values on b ( is even passing my internal validation ) but and insertion like this will fail:

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.fake_pofile);
Ball ball = new Ball(this,1, "Test", "Test", "", "");
ball.setImage(bm);
mHelper.updateBall(ball);
  • 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-23T15:39:16+00:00Added an answer on May 23, 2026 at 3:39 pm

    Well… as i didn’t, nobody else noted on the code for the table creation, between the field BALL_USERID i wasn’t leaving a space so it was a whole word, funny thing that db.exec is supposed to throw exceptions but in this case didn’t and accepted a strange name as a field with no type and created the table with no field “userId” but “useridinteger” with no type ( is there a default type if you don’t set one?? )

    Sometimes are just those litte things that can make you go nuts.

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

Sidebar

Related Questions

I've been searching all up and down google trying to find this as well
I've been fighting with this problem all day and am just about at my
I know this is a subject that has been well covered here and throughout
Ok well I have been fighting with this for a while now and have
OK, well I've been working on a simple app that allows users to save
Well I have been writing in the same style for awhile now and all
I have a WCF service that I am consuming, and have been doing well
My IDE has been working very well, until today. When I try to compile
Back again this time working with data providers. Well i been doing a bit
Well been working for hours today so i might be missing something silly, but,

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.