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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:13:37+00:00 2026-06-09T09:13:37+00:00

This is sets of methods which I use in DatabaseHandler class which extends from

  • 0

This is sets of methods which I use in DatabaseHandler class which extends from OrmLiteSqliteOpenHelper:

@Override
        public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) 
        {
         try
         {  

            TableUtils.createTable(connectionSource, Category.class);
            TableUtils.createTable(connectionSource, Level.class);
            DataParsing a = new DataParsing();
            a.wrapCategories();
            Log.i(DatabaseHandler.class.getName(), "created new entries in onCreate: " );
         }
         catch (SQLException e){
             Log.e(TAG, "error creating DB " + DATABASE_NAME);
             throw new RuntimeException(e);
         } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }
    // Upgrading database
      @Override
       public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVer, int newVer)
      {
           try
            {          

               TableUtils.dropTable(connectionSource, Category.class, true);
               TableUtils.dropTable(connectionSource, Level.class, true);
               onCreate(db, connectionSource);
            }
           catch (SQLException e){
               Log.e(TAG,"error upgrading db "+DATABASE_NAME+"from ver "+oldVer);
               throw new RuntimeException(e);
           }

       }


      public Dao<Category, Integer> getCategoryDao() throws SQLException 
        {
            if (simpleCategoryDao == null) {
                simpleCategoryDao = getDao(Category.class);
            }
            return simpleCategoryDao;
        }

      public Dao<Level, Integer> getLevelDao() throws SQLException 
        {
            if (simpleLevelDao == null) {
                simpleLevelDao = getDao(Level.class);
            }
            return simpleLevelDao;
        }

When I run my app I get such messages

08-03 16:44:08.619: V/droidDatabaseConnection(12196): AndroidDatabaseConnection@405182b0: compiled statement got AndroidCompiledStatement@40578b10: CREATE TABLE `categories` (`title` VARCHAR , `id` INTEGER , PRIMARY KEY (`id`) ) 
08-03 16:44:08.619: V/ndroidCompiledStatement(12196): compiled statement runExecute changed 1 rows: CREATE TABLE `categories` (`title` VARCHAR , `id` INTEGER , PRIMARY KEY (`id`) ) 

08-03 16:44:08.629: V/droidDatabaseConnection(12196): AndroidDatabaseConnection@405182b0: compiled statement got AndroidCompiledStatement@405f0f50: CREATE TABLE `levels` (`title` VARCHAR , `id` INTEGER , PRIMARY KEY (`id`) ) 
08-03 16:44:08.629: V/ndroidCompiledStatement(12196): compiled statement runExecute changed 1 rows: CREATE TABLE `levels` (`title` VARCHAR , `id` INTEGER , PRIMARY KEY (`id`) ) 

As I understand data base was created successfully. Then I want to put a List of objects there with the method:

public void saveContacts(List<Category> contacts) throws SQLException
    {

        OrmLiteSqliteOpenHelper dbHelper= DatabaseHandler.getInstance(_context);
        String res = Boolean.toString(dbHelper.isOpen());
        Log.i(" 123 ",res);
        dbHelper.getWritableDatabase();
        Dao<Category, Integer> daoContact=dbHelper.getDao(Category.class);

        QueryBuilder<Category, Integer> queryBuilder = daoContact.queryBuilder();
        daoContact.queryRaw("insert into categories values (hello, 1)");
        Log.i("dao",queryBuilder.selectColumns("title").prepare().toString());

        for (Category contact : contacts) {
            Log.i("dao",contact.toString());
            HelperFactory.GetHelper().getCategoryDao().createIfNotExists(contact);
        }
      }

And on row dbHelper.getWritableDatabase(); I get

08-03 16:44:29.199: E/AndroidRuntime(12196): FATAL EXCEPTION: main
08-03 16:44:29.199: E/AndroidRuntime(12196): java.lang.NullPointerException
08-03 16:44:29.199: E/AndroidRuntime(12196):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at com.assignmentexpert.LoginActivity.saveContacts(LoginActivity.java:268)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at com.assignmentexpert.LoginActivity$4.onClick(LoginActivity.java:132)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at android.view.View.performClick(View.java:2485)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at android.view.View$PerformClick.run(View.java:9080)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at android.os.Handler.handleCallback(Handler.java:587)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at android.os.Looper.loop(Looper.java:123)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at android.app.ActivityThread.main(ActivityThread.java:3687)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at java.lang.reflect.Method.invokeNative(Native Method)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at java.lang.reflect.Method.invoke(Method.java:507)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-03 16:44:29.199: E/AndroidRuntime(12196):    at dalvik.system.NativeStart.main(Native Method)

Why does it happen?

  • 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-09T09:13:39+00:00Added an answer on June 9, 2026 at 9:13 am
    public void saveContacts(List<Category> contacts) throws SQLException
    {
    
        OrmLiteSqliteOpenHelper dbHelper= DatabaseHandler.getInstance(_context);
        String res = Boolean.toString(dbHelper.isOpen());
        Log.i(" 123 ",res);
        dbHelper= this.getWritableDatabase(); <----- here change will may help you
        Dao<Category, Integer> daoContact=dbHelper.getDao(Category.class);
    
        QueryBuilder<Category, Integer> queryBuilder = daoContact.queryBuilder();
        daoContact.queryRaw("insert into categories values (hello, 1)");
        Log.i("dao",queryBuilder.selectColumns("title").prepare().toString());
    
        for (Category contact : contacts) {
            Log.i("dao",contact.toString());
            HelperFactory.GetHelper().getCategoryDao().createIfNotExists(contact);
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public abstract class MyControllerBase : Controller { protected override void OnActionExecuting(ActionExecutingContext context) { //
I have something like this: [Description(Sets the color.), Category(Values), DefaultValue(Color.White), Browsable(true)] public Color MyColor
This specific questions stems from the attempt to handle large data sets produced by
Question I use celery to launch task sets that look like this: I perform
I've got a class which abstracts performing long running methods on a background thread
response.Cookies( SOFTWARE_PROGRAM_NAME).Expires = datetime.now.adddays(365*10) this sets expiration for 10 years. Anyway to set it
This function sets up the Magento Grid to display a list of filenames with
I've inherited some python code that contains a rather cryptic decorator. This decorator sets
I am working with Django's generic views, specifically django.views.generic.date_based.archive_month . This views sets the
This code still sets the field to today's date <script type=text/javascript> $(document).ready(function () {

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.