UnsatisfiedLinkError in native method

纵然是瞬间 提交于 2019-11-29 05:06:59

I have resolved this issue my self by adding

System.loadLibrary("sqliteX");

To each method where they are created

LIKE THIS:

public HashMap<String, ArrayList<String>> word_quiz(String qry) {
    System.loadLibrary("sqliteX");
    ArrayList<String> list1 = new ArrayList<String>();
    ArrayList<String> list2 = new ArrayList<String>();
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH+ "/sk1.db", null);
    Cursor mcursor = db.rawQuery(qry, null);
    try {
        mcursor.moveToFirst();
        do {
            list1.add(mcursor.getString(0));
            list2.add(mcursor.getString(1));
        } while (mcursor.moveToNext());

    } catch (IndexOutOfBoundsException e) {
        if (MainActivity.logcat_status) {
            Log.e("Error", e + "");
        }
    }
    mcursor.close();
    mcursor = null;
    HashMap<String, ArrayList<String>> final_list = new HashMap<String, ArrayList<String>>();
    final_list.put("list1", list1);
    final_list.put("list2", list2);
    db.close();
    return final_list;

}

Now its working fine

I think I can also use a constructor to load the library "sqliteX"

Thanks guys for considering my question :)

The exception originates from your code at com.example.samplesqlitedb.MainActivity$2.onClick() at com/example/samplesqlitedb/MainActivity.java:56, but System.loadLibrary() is called from org.sqlite.app.customsqlite.CustomSqlite.run_the_tests(). There is no evidence that the org.sqlite.app.customsqlite.CustomSqlite activity was even loaded into JVM when this happened.

I would suggest to load libsqliteX.so from the static constructor of org.sqlite.database.sqlite.SQLiteConnection class. Maybe you can find some better place - e.g. com.example.samplesqlitedb.SearchDataDB class, or the class in your app that extends android.app.Application (if you have such).

As opposed to the accepted answer consider inserting the call to the System.loadLibrary function only once, e.g. into the DbHelper.

public class MyDbHelper extends SQLiteOpenHelper {

   static {
      System.loadLibrary("sqliteX");
   }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!