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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:57:29+00:00 2026-05-31T14:57:29+00:00

I followed a tutorial on how to handle SQLite databases using the android SDK.

  • 0

I followed a tutorial on how to handle SQLite databases using the android SDK. My Problem is that the application crashes when i call the method “getUsername()”. What am I doing wrong?

package racenet.racenet;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class Preferences extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 2;
    private static final String DATABASE_NAME = "racenet.racenet.db";

    Preferences(Context context) {

        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("CREATE TABLE settings(key TEXT, value TEXT)");

        values = new ContentValues();
        values.put("user_name", "");
        getWritableDatabase().insert("settings", null, values);
    }

    @Override
    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {

    }

    public String getUsername() {

        Cursor c = getReadableDatabase().query("settings", new String[]{"value"},
            "key = 'user_name'", null, null, null, null);
        c.moveToFirst();
        String username = c.getString(0);
        c.close();
        return username;
    }
}
  • 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-31T14:57:30+00:00Added an answer on May 31, 2026 at 2:57 pm

    Hi, try this:

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE settings (key TEXT, value TEXT);");
    
        values = new ContentValues();
    
        // First argument of the put method is a column name
        // Second argument is an inserted value
        values.put("key", "user_name");
        values.put("value", "user_value");
    
        db.insert("settings", null, values);
    }
    
    // This method will drop your table and create a new one if you have changed 
    // the database version
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS settings");
    
        onCreate(db);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a compiling problem. I followed tutorial about Hello world program for Android
So i followed this tutorial to set up the android facebook sdk in my
I followed this tutorial and got problem that certificate has expired. I looked up
I followed this tutorial: https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf However, I can't seem to set the path right.
I followed this tutorial here: http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/ It works great but when I enable CSRF
I followed a tutorial that went like so: ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
I have followed this tutorial which allowed me to create a Silverlight DataGrid that
i had followed exactly same procedure on google's tutorial: http://developer.android.com/guide/tutorials/views/hello-mapview.html ...while i got force
I've followed a standard tutorial for building a database with Android. I've created a
I am trying to develop a chat application. I used AsyncSocket and followed tutorial.

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.