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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:15:21+00:00 2026-06-16T22:15:21+00:00

I’m having problems with inserting values into my Android SQLite database’s table. I’ve already

  • 0

I’m having problems with inserting values into my Android SQLite database’s table. I’ve already tried adapting a few tutorial examples but to no avail. Could someone take a look at my code to point out what should I change to make it work? Here is code of my class:

public class Baza extends SQLiteOpenHelper {
SQLiteDatabase db;
static final String dbName ="MyDb";
static final int dbVersion = 1;

// tabela przepisy
static final String TabName = "Przepisy";
static final String TabCol1 = "id";
static final String TabCol2 = "Nazwa";
static final String TabCol3 = "Kategoria";

static final String dbCreate = "CREATE TABLE" + TabName + "(" + 
    TabCol1+ " INTEGER PRIMARY KEY, "+
    TabCol2+ " TEXT, " +
    TabCol3+ " TEXT)";

public Baza(Context context) {
    super(context, dbName, null, dbVersion);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    db.execSQL(dbCreate);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    db.execSQL("DROP TABLE IF EXISTS "+ TabName);
}

public boolean insert(String name, String cat)
{
    db = super.getWritableDatabase();
     ContentValues cv=new ContentValues();

       cv.put(TabCol2, name);
       cv.put(TabCol3, cat);

       long isAdded = db.insert(TabName, null, cv);
       if (isAdded == -1)       return false;
       else return true;
}
}

I’d be grateful for any help.

Logcat error:

 I/Process(1289): Sending signal. PID: 1289 SIG: 9
 D/AndroidRuntime(1318): Shutting down VM
 W/dalvikvm(1318): threadid=1: thread exiting with uncaught exception (group=0x40015560)
 E/AndroidRuntime(1318): FATAL EXCEPTION: main
 E/AndroidRuntime(1318): java.lang.NullPointerException
 E/AndroidRuntime(1318):    at com.example.mojabaza.Baza.insert(Baza.java:60)
 E/AndroidRuntime(1318):    at com.example.mojabaza.Mojabaza$2.onClick(Mojabaza.java:45)
 E/AndroidRuntime(1318):    at android.view.View.performClick(View.java:2485)
 E/AndroidRuntime(1318):    at android.view.View$PerformClick.run(View.java:9080)
 E/AndroidRuntime(1318):    at android.os.Handler.handleCallback(Handler.java:587)
 E/AndroidRuntime(1318):    at android.os.Handler.dispatchMessage(Handler.java:92)
 E/AndroidRuntime(1318):    at android.os.Looper.loop(Looper.java:123)
 E/AndroidRuntime(1318):    at android.app.ActivityThread.main(ActivityThread.java:3683)
 E/AndroidRuntime(1318):    at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(1318):    at java.lang.reflect.Method.invoke(Method.java:507)
 E/AndroidRuntime(1318):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 E/AndroidRuntime(1318):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 E/AndroidRuntime(1318):    at dalvik.system.NativeStart.main(Native Method)
  • 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-16T22:15:22+00:00Added an answer on June 16, 2026 at 10:15 pm

    You are missing a space and I am not sure AUTO INCREMENT is two words:

    "CREATE TABLE" + TabName + "(" + 
        TabCol1+ " INTEGER PRIMARY KEY AUTO INCREMENT, "+
    

    Use:

    //    Added: v
    "CREATE TABLE " + TabName + "(" + 
        TabCol1+ " INTEGER PRIMARY KEY, "+ // autoincrement is implied as well as `not null`
    

    Depending on the error you may need to set dbVersion equal to 2 build this new schema.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a reasonable size flat file database of text documents mostly saved in

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.