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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:51:58+00:00 2026-06-09T13:51:58+00:00

I have an class Category @DatabaseTable(tableName = categories) public class Category { public final

  • 0

I have an class Category

  @DatabaseTable(tableName = "categories")
public class Category {
    public final static String CATEGORY_TITLE_FIELD_NAME  = "title";
    @SerializedName("id")
    @DatabaseField(id = true)
    int id;
    @SerializedName("title")
    @DatabaseField(dataType = DataType.STRING, columnName = CATEGORY_TITLE_FIELD_NAME)
    String title;
    // need for ORMlite
    public Category()
    {}
    public Category (int id, String title)
    {
        this.id = id;
        this.title = title;
    }
    public int getCategoryId() 
    {

         return this.id;
    }

    public String getCategoryTitle() 
    {
         return this.title;
    }

    public void setCategoryId(int id)
    {
         this.id = id;
    }

    public void setCategoryTitle(String title)
    {
         this.title = title;
    }

    @Override
    public String toString()
    {       
    return "{title="+title +" "+"id="+id+"}";   
    }

}

And I put data to it from JSON and want to save it in the ORMLite. This is how I do it:

DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject data = json.getJSONObject(KEY_DATA);
// getting categories
JSONArray categories = new JSONArray();
categories = data.getJSONArray(KEY_CATEGORIES);
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonArray array = parser.parse(categories.toString()).getAsJsonArray();
Type listType = new TypeToken<List<Category>>() {}.getType();
List<Category> tasks = new ArrayList<Category>();
tasks = gson.fromJson(array.toString(), listType);
RuntimeExceptionDao<Category, Integer> simpleDao = getHelper1().getSimpleCategoryDao();
Dao<Category, Integer> categoryDao = getHelper1().getCategoryDao();
saveContacts(tasks);
List<Category> list = categoryDao.queryForAll();
Log.i("categoryDAO",list.toString());

And this is saveContacts() method for data saving:

 public void saveContacts(List<Category> contacts) throws SQLException
    {
        OrmLiteSqliteOpenHelper dbHelper= DatabaseHandler.getInstance(_context);
        Dao<Category, Integer> daoContact=dbHelper.getDao(Category.class);
        for (Category contact : contacts) {
            daoContact.create(contact);
        }
        dbHelper.close();
    }

But I’ve got such exception as:

 FATAL EXCEPTION: main
java.lang.NullPointerException
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
at com.j256.ormlite.android.AndroidConnectionSource.getReadWriteConnection(AndroidConnectionSource.java:63)
    at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:304)
    at com.assignmentexpert.LoginActivity.saveContacts(LoginActivity.java:192)
    at com.assignmentexpert.LoginActivity$1.onClick(LoginActivity.java:108)
    at android.view.View.performClick(View.java:2485)
    at android.view.View$PerformClick.run(View.java:9080)
    at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)

Please, tell what I’m doing wrong?

  • 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-09T13:51:59+00:00Added an answer on June 9, 2026 at 1:51 pm

    Problem solved passing context to my DatabaseHandler that extends from OrmLiteSqliteOpenHelper.

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

Sidebar

Related Questions

I have 2 clases: public class products { public string category; public string name;
I have a class : class Category { String name SortedSet items static hasMany
I have the following class: public class Category { public string Name { get;
I have designed a Class for Parent Child relationship class Category { public string
I have a domain class like public class Category { [Key] public string IdCategory
I have a Category class which looks like this: @Entity @Table(name = categories) public
I have select: = f.select(:category_id, @categories, :html_options => {:class => 'select_box'}, {:disabled => true
For edit home status of category I have a link: <span class=\ha\ title=\Active in
Imagine you have this model: class Category(models.Model): node_id = models.IntegerField(primary_key = True) type_id =
I have 2 models: class Video < ActiveRecord::Base belongs_to :categories, :foreign_key => category, :class_name

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.