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

The Archive Base Latest Questions

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

I parsed data from json to corresponding class data and them want to save

  • 0

I parsed data from json to corresponding class data and them want to save it in the ORMLite… Here my classes

public class Categories {
    ArrayList<Category> categories;

     public Categories() {
        categories = new ArrayList<Category>();
     }

      public ArrayList<Category> getCategories() { 
          return this.categories; 
     }
}

and Levels:

@DatabaseTable(tableName = "levels")
public class Level {
    @SerializedName("id")
    @DatabaseField(id = true)
    int id;

    @SerializedName("title")
    @DatabaseField(dataType = DataType.STRING)
    String title;

    public Level() { }

    public Level(int id, String title) {
         this.id = id;
         this.title = title;
     }
}

OnCreate method in DatabaseHandler class:

@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
     try {  
        TableUtils.createTable(connectionSource, Category.class);
        TableUtils.createTable(connectionSource, Level.class);
     } catch (SQLException e){
         Log.e(TAG, "error creating DB " + DATABASE_NAME);
         throw new RuntimeException(e);
     }
}

And DAO methods in DatabaseHandler:

 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;
    }

    public RuntimeExceptionDao<Category, Integer> getSimpleCategoryDao() {
        if (categoryRuntimeDao == null) {
            categoryRuntimeDao = getRuntimeExceptionDao(Category.class);
        }
        return categoryRuntimeDao;
    }

    public RuntimeExceptionDao<Level, Integer> getSimpleLevelDao() {
        if (levelRuntimeDao == null) {
            levelRuntimeDao = getRuntimeExceptionDao(Level.class);
        }
        return levelRuntimeDao;
    }

I parse my data from JSON in my Activity that way:

 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 = databaseHandler.getCategoryDao();
         Log.i("categoryDAO",categoryDao.queryForAll().toString());

    // getting levels
    JSONArray jsonlevels =new JSONArray();
    jsonlevels = data.getJSONArray(KEY_LEVELS); 
    JsonArray levelsarray = parser.parse(jsonlevels.toString()).getAsJsonArray();
    Type listlevels = new TypeToken<List<Level>>() {}.getType();
    List<Level> levels = new ArrayList<Level>();
    levels = gson.fromJson(levelsarray.toString(), listlevels);
    Log.i("levelsgson",levels.toString());
    RuntimeExceptionDao<Level, Integer> levelDao = getHelper1().getSimpleLevelDao();
    Log.i("levelDAO",levelDao.toString());
    Dao<Level, Integer> levelsDao = databaseHandler.getLevelDao();
    Log.i("levelsDAO",levelsDao.queryForId(3).toString());

I get Category data successfuly, but I’ve got exception when want to call queryForId() for Level DAO instance.
Got such exception:

 java.sql.SQLException: queryForOne from database failed: SELECT * FROM `levels` WHERE `id` = ?
    at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
    at com.j256.ormlite.android.AndroidDatabaseConnection.queryForOne(AndroidDatabaseConnection.java:169)

at com.j256.ormlite.stmt.mapped.MappedQueryForId.execute(MappedQueryForId.java:38)
at com.j256.ormlite.stmt.StatementExecutor.queryForId(StatementExecutor.java:84)
at com.j256.ormlite.dao.BaseDaoImpl.queryForId(BaseDaoImpl.java:219)
at com.assignmentexpert.LoginActivity$1.onClick(LoginActivity.java:119)
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)
      Caused by: android.database.sqlite.SQLiteException: no such table: levels: , while compiling: SELECT * FROM `levels` WHERE `id` = ?
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
at com.j256.ormlite.android.AndroidDatabaseConnection.queryForOne(AndroidDatabaseConnection.java:155)
... 15 more

So the problem is that ‘levels’ table can’t be creating. Don’t understand why if I use equal mechanism as for Category table..


After some analysis I understand that problem is in this method

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

        OrmLiteSqliteOpenHelper dbHelper= DatabaseHandler.getInstance(_context);
        Dao<Category, Integer> daoContact=dbHelper.getDao(Category.class);

        QueryBuilder<Category, Integer> queryBuilder = daoContact.queryBuilder();
        Log.i("dao",queryBuilder.selectColumns("title").prepare().toString());


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

    }

On the create() row. It throws such set of exceptions as :

    FATAL EXCEPTION: main
 java.lang.NullPointerException
    at com.library.DataParsing.saveContacts(DataParsing.java:61)
    at com.library.DataParsing.fillCategories(DataParsing.java:45)
    at com.library.DatabaseHandler.onCreate(DatabaseHandler.java:85)
    at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.onCreate(OrmLiteSqliteOpenHelper.java:169)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:126)
at com.j256.ormlite.android.AndroidConnectionSource.getReadWriteConnection(AndroidConnectionSource.java:63)
    at com.j256.ormlite.android.AndroidConnectionSource.getReadOnlyConnection(AndroidConnectionSource.java:51)
    at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:202)
    at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:155)
    at com.j256.ormlite.stmt.StatementExecutor.queryForAll(StatementExecutor.java:113)
    at com.j256.ormlite.dao.BaseDaoImpl.queryForAll(BaseDaoImpl.java:237)
    at com.assignmentexpert.LoginActivity$1.onClick(LoginActivity.java:97)
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)

Help with it please…

  • 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:46:31+00:00Added an answer on June 9, 2026 at 1:46 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 want a method that extracts the data from a JSON-object parsed before as
I am getting DataTables warning: JSON data from server could not be parsed. This
Any one has done this, i want to get data parse from the JSON
I'm trying to load and parse json data from an external source into a
I have a flash file which loads data from JSON and parses it. It
... // result is a JSON data passed to this function from outside var
I have a thousands of data parsed from huge XML to be inserted into
I am writing an objective-c model to hold all of the data parsed from
eSo I've got some parsed php data whiched I've fetched from my database and
I use this bit of code to feed some data i have parsed from

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.