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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:40:18+00:00 2026-06-16T16:40:18+00:00

This code crashes the application, If i refer to database name from the static

  • 0

This code crashes the application, If i refer to database name from the static variable it works. When i try to get it from the strings.xml it crashes the app. Any idea why it fails? This is a class not an activity so i imported android.content.res.Resources. Also if i try context.getString it will also crash.

import android.content.Context;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

//public static final String DATABASE_NAME = "library.db";
public static final String TITLE = "title";
public static final String AUTHOR = "author";
public static final String ISBN = "isbn";


public DatabaseHelper(Context context) {
    super(context, Resources.getSystem().getString(R.string.DATABASE_NAME), null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE books (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, author TEXT, isbn TEXT);");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

}

  • 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-16T16:40:22+00:00Added an answer on June 16, 2026 at 4:40 pm

    You don’t need to use a string resource for your database name, and in fact it doesn’t make much sense to. String resources are mainly for anything the user will see so that you can provide alternative resources for other configurations (specifically, other languages). What you are providing is essentially a file name for your database. Since this is entirely internal to your app and the user will never see it, you should just use a static final String with the name you want for your database file.

    /* Database file name */
    private static final String BD_NAME = "something.db";
    
    public DatabaseHelper(Context context) {
        super(context, DB_NAME, null, null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application crashes when i put background line like in this code. When i
In my C++/WinAPI application I get the My Documents folder path using this code:
If i try to use this simple code: - (void)applicationDidFinishLaunching:(UIApplication *)application { // Add
When i run this code application crashes. #import HelloWorldLayer.h CCSprite *background,*ball; CGSize size; #define
Im using this code to get data from QTcpSocket. I read data in buffer
I am using this code for table delegates my application crashes when I scroll
I've been struggling with this for a while now, and this code crashes with,
my app crashes with this code.. it doesnt even start up.. any ideas guys
I added this part of the code in my onCreate() method and it crashes
This code is the core of a much larger script that works great 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.