Java Error - Catching System.load ()

My main ():

System.out.println("Start loading libraries");
boolean b2 = false;
try{
  b2 = FileManager.loadBinaries();
} catch (Exception e){
  System.out.println("Exception on loading");
}
System.out.println("Libraries loading ended");

LoadBinaries ():

public static boolean loadBinaries(){
    String os = System.getProperty("os.name").toLowerCase();
    ArrayList<String> bins = new ArrayList<String>();

    if(os.indexOf("windows 7") >= 0 || os.indexOf("windows vista") >= 0){
        bins.add("/nm/metadata/bin/win/libcurld.dll");
        bins.add("/nm/metadata/bin/win/libfftw3f-3.dll");
        bins.add("/nm/metadata/bin/win/libmad.dll");
        bins.add("/nm/metadata/bin/win/libsamplerate.dll");
        bins.add("/nm/metadata/bin/win/seven/mylib.dll");
    }
    else if(os.indexOf("windows xp") >= 0){
        bins.add("/nm/metadata/bin/win/libcurld.dll");
        bins.add("/nm/metadata/bin/win/libfftw3f-3.dll");
        bins.add("/nm/metadata/bin/win/libmad.dll");
        bins.add("/nm/metadata/bin/win/libsamplerate.dll");
        bins.add("/nm/metadata/bin/win/xp/mylib.dll");
    } else if(os.indexOf("mac") >= 0){
        return false;
    }

    File f = null;
    for(String bin : bins){
        InputStream in = FileManager.class.getResourceAsStream(bin);
        byte[] buffer = new byte[1024];
        int read = -1;
        try {
            String[] temp = bin.split("/");
            f = new File(LIB_FOLDER + "/" + temp[temp.length-1]);
            File realF = new File(f.getAbsolutePath());

            if(!realF.exists()){
                FileOutputStream fos = new FileOutputStream(realF);

                while((read = in.read(buffer)) != -1) {
                    fos.write(buffer, 0, read);
                }
                fos.close();
                in.close();
            }
            System.out.println("Hello Load");
            System.load(f.getAbsolutePath());
            System.out.println("Bye Load");
        } catch (Exception e) { System.out.println("Bye Exception"); FileManager.log(e.getMessage(), true); librariesLoaded = false; return false; }
    }

    System.out.println("Bye Method");
    librariesLoaded = true;
    return true;
}

When I run this main, I get the following output:

Start loading libraries
Hello Load
Bye Load
Hello Load
Bye Load
Hello Load
Bye Load
Hello Load
Bye Load
Hello Load
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\java\workspace\Lib\mylib.dll: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at nm.player.FileManager.loadBinaries(FileManager.java:264)
    at nm.player.Player.<init>(Player.java:88)
    at nm.player.Player.main(Player.java:523)

This error occurs due to the lack of some C ++ system dlls. But this is not my problem. I am worried about where the program goes after this error! I do not see print on the catch, print after the cycle in the method, and neither prints on the main, nor after loading.

How can I catch this type of error and deal with it? Example. When this error occurs, I want to print "please C ++ built-in libraries" and control the flow after it.

+5
source share
3 answers

Try replacing

catch (Exception e)

at the bottom of your method loadBinaries()with

catch (UnsatisfiedLinkError e)

UnsatisfiedLinkError Error, Exception: Error Exception - Throwable, Java.

Error s. , , , , : " X , , ".

+15

UnsatisfiedLinkError, Exception , , catch. , , catch catch(Error e).

, Java . : Exception Error, Throwable. , , , Throwable ( ).

RuntimException, , Exception.

+3

All Articles