0

Testing presence of videeditor_jni Native Library in system libraries by

static {
    try {
        if (System.getProperty("videoeditor_jni") != null) {
            System.loadLibrary("videoeditor_jni");
        } else {
            PreferenceManager.setLibraryFlag(false);

        }
    } catch (Exception e) {
        PreferenceManager.setLibraryFlag(false);
    }

}

while running this code i've got UnsatisfiedException on library in logcat. though I've put conditions and try..catch it is checking if condition and then Force Close. why didn't go into catch?? any reason? tried UnsatisfiedException, RuntimeException, Exception, Error but not anything called in catch.. need help .

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
WonderSoftwares
  • 2,800
  • 1
  • 15
  • 21
  • 1
    Comment this PreferenceManager.setLibraryFlag(false); And try e.printStackTrace() – Amsheer Jun 19 '15 at 06:25
  • tried that..also trie to log and debug also..but still not reached at catch.., – WonderSoftwares Jun 19 '15 at 06:31
  • Make your method unstatic, read [here](http://stackoverflow.com/questions/2070293/why-doesnt-java-allow-to-throw-an-exception-from-static-initialization-block) for more info – Strider Jun 19 '15 at 06:34
  • give the exception stack-trace you get, and tell us which line in the code you showed here is which line-number in your code – hoijui Jun 19 '15 at 06:41
  • @Strider he is not trying to throw an exception from the static block, he is trying to catch it in there, which is fine. – hoijui Jun 19 '15 at 06:42
  • Just as an info: **UnsatisfiedLinkError** is not a child class of **Exception**, so it is normal if you just use the generic **Exception** not to catch **UnsatisfiedLinkError**. – dragi Jun 19 '15 at 07:17
  • 1
    @hoijui you are right, I misunderstood the question, my bad ;) – Strider Jun 19 '15 at 07:38

1 Answers1

0

To Catch exception stackTrace use method printStackTrace(). like as belows

write this Application class onCreate method.

public void onCreate()
    {
super.onCreate();
....

        try {
            if (System.getProperty("videoeditor_jni") != null) {
                System.loadLibrary("videoeditor_jni");
            } else {
                PreferenceManager.setLibraryFlag(false);

            }
        } catch (Exception e) {
          e.printStackTrace.
        }

    }
Praveen Sharma
  • 4,326
  • 5
  • 25
  • 45
  • tried this. returned from if condition..not moving ahead or didn't reach catch clause. even not printing log at catch and not reachable by debug mode. – WonderSoftwares Jun 19 '15 at 06:36
  • try to execute this on Application class onCreate() – Praveen Sharma Jun 19 '15 at 06:37
  • @pravin Sharma Putting these conditions in Appliction onCreate() is always going to else condition though it sholt go to if condition because **videoeditor_jni** is present and working . – WonderSoftwares Jun 19 '15 at 07:15
  • if its present then it must be execute in static and non static both block. – Praveen Sharma Jun 19 '15 at 07:16
  • in both conditions static and nonstatic **System.getProperty("videoeditor_jni") ** returns null . somewhere it loads successfully because it is used ahead and working well. can't understand why System.getproperty returns null – WonderSoftwares Jun 19 '15 at 07:24