Java Question Error parsing libraries - Object reference not set to an instance of an object.

qle

Member
Licensed User
Longtime User
Hi,
I think trying to create a library from this SDK may have me beat.. i just dont have the skill level.

In my library java code i added a class within my class,
B4X:
    private Barcode1D mInstance;[/INDENT]
public class c4000{
    private boolean isOpened = false;
    public int DeviceControlinit () throws IOException
    {
 
        try {
            //get 1D instance
            mInstance = Barcode1D.getInstance();
           //This actually now works thanks to DonManFred (well, i dont get an error)
            return 1;
        } catch (Exception e) {
            e.printStackTrace();

            return 0;
        }
    }


    public int openscanner () throws IOException
    {
            new InitTask().execute();
        return 1;
    }

    public class InitTask extends AsyncTask<String, Integer, Boolean> {

        @Override
        protected Boolean doInBackground(String... params) {
            // TODO Auto-generated method stub
            return mInstance.open();
        }

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            isOpened = result;

        }
    }

    etc.......
}

It is when i added the class,
public class InitTask extends AsyncTask<String, Integer, Boolean> {
now causes a problem when i try to load the library in A4B, i get
c4000_lib_load_Error.jpg


Any help is very appreciated.

Lee.
in above my head...​
 
Last edited:

qle

Member
Licensed User
Longtime User
Adding the @Hide caused the SLC to throw an error on compile.
B4X:
public int openscanner () throws IOException
    {
        new InitTask().execute();
        return 1;
    }

    @Hide
    public class InitTask extends AsyncTask<String, Integer, Boolean> {

        @Override
        protected Boolean doInBackground(String... params) {
            // TODO Auto-generated method stub
            return mInstance.open();
        }

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            isOpened = result;

        }
    }

SLC reports
B4X:
Starting step: Compiling Java code.
javac 1.7.0_51
C:\Users\Lee\workspace\Serial_c4000\src\com\android\barcode1d\c4000.java:77: error: cannot find symbol
    @Hide
     ^
  symbol:   class Hide
  location: class c4000
1 error

So.. i removed the hide and changed the public class InitTask to private class InitTask
This then compiled ok, and B4A loaded the library without error.

I could even call the .openscanner that calls the private InitTask, and it returns a 1 to B4A ok..

But then, it throws an error
B4X:
DeviceControlinit1
Open1
java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:278)
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ExceptionInInitializerError
    at com.rscja.deviceapi.Barcode1D.open(SourceFile:52)
    at com.android.barcode1d.c4000$InitTask.doInBackground(c4000.java:83)
    at com.android.barcode1d.c4000$InitTask.doInBackground(c4000.java:78)
    at android.os.AsyncTask$2.call(AsyncTask.java:264)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    ... 5 more
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load DeviceAPI: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
    at java.lang.System.loadLibrary(System.java:535)
    at com.rscja.deviceapi.DeviceAPI.<clinit>(SourceFile:526)
    ... 10 more
I seem to be back to this java.lang.UnsatisfiedLinkError: Couldn't load DeviceAPI:

yet the DeviceControlinit worked! (mInstance = Barcode1D.getInstance();) and this uses the DeviceAPI

Lee.

EDIT: Looking through the logs i see while loading the libDeviceAPI.so library that it sys "skipping init"

B4X:
Trying to load lib /data/data/pos.c4000/files/libDeviceAPI.so 0x417ca960
Added shared lib /data/data/pos.c4000/files/libDeviceAPI.so 0x417ca960
No JNI_OnLoad found in /data/data/pos.c4000/files/libDeviceAPI.so 0x417ca960, skipping init
** Activity (main) Create, isFirst = true **

is this a clue?
does skipping init mean it failed to load?
and what is No JNI do i need it?

Lee.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User

qle

Member
Licensed User
Longtime User
Thank you

edit: This allowed it to complile as a public class,
B4X:
    @Hide
    public class InitTask extends AsyncTask<String, Integer, Boolean> {

But back to same issue.
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load DeviceAPI: findLibrary returned null


Lee.
 
Last edited:

qle

Member
Licensed User
Longtime User
Im trying both Eclipse and SLC. (both give the same results)

In eclipse the .so file is in
/lib/armeabi/libDeviceAPI.so
and the DeviceAPI.jar is in
/lib/DeviceAPI.jar
(in eclipse i have added the /lib/DeviceAPI.jar as a referenced library)

With SLC the .so file is in
/lib/armeabi/libDeviceAPI.so
and
/additional/lib/libDeviceAPI.so
and the DeviceAPI.jar is in
/lib/DeviceAPI.jar
and
/additional/lib/DeviceAPI.jar


I load the libDeviceAPI.so from the java library with
B4X:
static {
    //System.loadLibrary("serial_port");
    try {
       if (File.Exists(File.getDirInternal(), "libDeviceAPI.so") == true){
           //Log.i(TAG,"About to load: libDeviceAPI.so");
           System.load(File.Combine(File.getDirInternal(), "libDeviceAPI.so"));
           //Log.i(TAG,"Afterload: libDeviceAPI.so"); 
       }else{.........

edit: i also added the libDeviceAPI.so and DeviceAPI.jar into the files of the A4B project.
And the DeviceAPI.jar to the <program files>\Anywhere Software\Basic4android\Libraries

Lee.
 
Last edited:

qle

Member
Licensed User
Longtime User
In the Java library i put
B4X:
static {
        try {
               if (File.Exists(File.getDirInternal(), "libDeviceAPI.so") == true){
                     Log.i(TAG,"About to load: DeviceAPI");
                     System.loadLibrary("DeviceAPI");   //throws UnsatisfiedLinkError
                     //System.load(File.Combine(File.getDirInternal(), "libDeviceAPI.so")); // this loads ok, no errors loading (but get UnsatisfiedLinkError in InitTask: doInBackground)
........
throws error:
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load DeviceAPI: findLibrary returned null


In SLC the dir structure for libs is
c_4000.dir_add.JPG
and in armeabi
c_4000.dir_lib.JPG


Lee.
 
Last edited:

qle

Member
Licensed User
Longtime User
Oh my,
i missed that... i assumed because in the eclipse it was /libs that in the /additional would be also /libs (i copy and paste the folder!)... and i did not even notice... unbelievable!

This got me to the next step... thank you!


The file.exists is from at older project where i had to System.load the .so from the File.getDirInternal() to get it to work, if it was not there then it would copy it from File.getDirAssets(). (this actually worked!) i had assumed i may have to do the same with this .so...

Im not great at java... but im learning..

Thank you for your help.

edit: WhooHoo!.. it all works... SLC is indeed a very good utility for building libraries from 3rd party SDK's. (i still cant believe i missed the libs<>lib bit...)
 
Last edited:
Top