Couldn't find "liballjoyn_java.so" - java

I'm working on an android chat room with alljoyn service. In the libs folder I have created the folder armeabi and added the liballjoyn_java.so file there.
I have added the dependencies necessary but I keep getting this error:
Couldn't find "liballjoyn_java.so"
when I try to load the library:
static {
Log.i(TAG, "System.loadLibrary(\"alljoyn_java\")");
System.loadLibrary("alljoyn_java");
}
I don't know where the problem is.

I think your java-library-path is unable to locate the alljoyn_java folder.
try using
System.load(absolute path to the alljoyn_java folder)
alljoyn_java folder must be in the
core->alljoyn folder

Related

Can not find file that is in resource folder - java

I have a question regarding file handling.
I automate a page using selenium, and I need to upload a file in this page.
I want to put the file in resource folder and read it's path in the test (since many OS and path will be different to any computer WIN/MAC).
I put the file manually in the resource folder, and it put it in:
X:\Project_11_01_2021\src\test\resources
when I used the ClassLoader and try to find the file it not found it,
I saw that if I manually put it in this path it find it, found.
X:\Project_11_01_2021\out\test\resources
the problem is that I am using git and if I add to the resources it upload to git and every one will get the change, and when I put in out\test\resources it is not displayed in the source tree to commit to git.
is their a way that classLoader will search in the first location? and not in the second?
[][path that worked]
[][when here not worked]
/******* test *******/
public void entertax() throws Exception {
WebDriver deiver2 = getWebDriver();
Thread.sleep(1000);
ClassLoader classLoader = getClass().getClassLoader();
String path = classLoader.getResource("TAX12.pdf").getPath();
System.out.println("\n\n path is " + path);
deiver2.switchTo()
.activeElement();
deiver2.findElement(By.xpath("//input[#type='file']"))
.sendKeys(
"X:\\Project_11_01_2021\\out\\test\\resources\\fw8TAX12.pdf");
System.out.println("END");
}
This issue looks more like an IDE configuration problem.
Your code classLoader.getResource("TAX12.pdf") looks correct (1. using classLoader.getResource() method && 2. specifying the correct relative path within the resources folder).
I assume why the code fails to find the file is due to the fact that the resources folder is not part of your applications classpath (I'm assuming your trying to run the code from your IDE which apparently seems to be IntelliJ).
I'm not regularly using IntelliJ, but you can specify the classpath settings in the Module settings.
In the Module settings specify the resources folder as a resource:
When successfully added the resources folder to the classpath it should display an icon like this in the project explorer:
After adding the resources folder to your classpath everything should work.
EDIT:
In case you're using Maven also make sure to specify the resources folder as such in the pom.xml file correspondingly.
Also make sure to spell the name of the file you're looking for "TAX12.pdf" correctly, since it seems to differ in your code and in your screenshots (not sure if it differs only because posting it here or also in your real code base).

How do I use a classloader to get inputstream on a model.zip file where the zip file is wrapped in a .jar file in classpath

The issue:
We have a jetty web-app, and in the application-code, I am trying to access a zip within a jar in classpath. Here's the jar in the libs folder:
/path/to/app/x.x.0-SNAPSHOT/apps/libs/my-model.jar
where my-model.jar is really just an empty folder with model.zip file inside it. If I extract this jar, I get johnsnow/mymodel.zip
My application code tries to access this zip as:
getClass().getResourceAsStream("johnsnow/mymodel.zip")
but of course, I don't get a proper handle to this resource and wind up getting a nullpointer exception. What am I doing wrong? Shouldn't I be able to access a file within a jar file in classpath using the getClass().getResourceAsStream() method?
Footnote:
Because model.zip was too large, we decided against shipping it with the code base. Thus we pushed it into a nexus repository, and reference the jar via a gradle compile dependency as follows:
compile "com.company.group.nlp:my-model:1.0#jar"
The fact that building the distribution pulls this jar, and puts it in apps/libs tells me that gradle does its part (of downloading the dependency to a classpath). The issue remains that I can't seem to find a way to access mymodel.zip inside my-model.jar
Try adding a slash to the file path:
getClass().getResourceAsStream("/johnsnow/mymodel.zip");
It will tell java to start looking for the class from the root folder, not from the current class package.

Android java.lang.UnsatisfiedLinkError with native library

I tried to use some native library and received some Exception with underlying exception UnsatisfiedLinkError:
java.lang.UnsatisfiedLinkError: Couldn't load viblast: findLibrary returned null
I am using Android Studio + gradle.
It looks like android can't find the native library in APK file.
My projects tree:
I tried to put them in "jniLibs" directory, but it doesn't helped me. I think I forget to write something in gradle files, but I can't figure out what.
Create Folder "jniLibs" inside your "src/main/" and put all your .so files inside "src/main/jniLibs" folder. In your screenshot I can't find "jniLibs".
Please follow below steps :
Add the path of your NDK in the local.properties file, located to
the root directory of your project.
add these lines to your app build.grade files :
sourceSets {
main {
jni.srcDirs = ["libs"]
}
}
Remove old .so files from your app.
Go to the directory src/jni directory of your app project and run the command :
PATH_TO_YOUR_NDK/ndk-build
The project is compiling and your get your lib (.so) under the directory libs of your modules.
5.the libraries into your main app should be like below structure.
Please for reference visit this link..!!
Thanks..!!

android sqlcipher java.io.FileNotFoundException: icudt46l.zip

The directory structure is as follows
Test
app
libs
commons-codec.jar
guava-r09.jar
sqlcipher.jar
src
main
java
jniLibs
armeabi
libdatabase_sqlcipher.so
libsqlcipher_android.so
libstlport_shared.so
x86
libdatabase_sqlcipher.so
libsqlcipher_android.so
libstlport_shared.so
Now, it keeps giving me the Exception java.io.FileNotFoundException: icudt46l.zip no matter where I put it.
I have tried putting assets\icudt46l.zip in Test\app, Test\app\libs, Test\app\src, Test\app\src\main, Test\app\src\main\jniLibs but the Exception persists.
Where should I put the folder "assets" which contains the zip file?
Now, it keeps giving me the Exception java.io.FileNotFoundException: icudt46l.zip no matter where I put it.
Given your project structure, put it in Test/app/src/main/assets/. IOW, you will need to create an assets/ directory that is a peer of your java/ directory, and put the ZIP file in there.

getClass().getResource() always returning null

I am trying to set the URL of an image that is located in my resource folder in my src folder. It is always setting the URL to null. The image is there and everything is named correctly. What is the issue? Thanks!
My file structure:
sp1
src
resources
01.png
Here is my code where I am trying to set the URL for the picture:
this.setImagePath(getClass().getResource("/resources/01.png"));
And the setImagePath is doing this, I am sure this is not the problem, because I followed the execution and it is setting it equal to null.
public final void setImagePath(URL imagePath) {
this.imagePath = imagePath;
}
Solution
I had to clean the build and rebuild. It worked after that fix.
I had to clean the build and then rebuild. Works now.
You need to check that, however you're building, the image file gets copied over to wherever the class files are compiled to. I.e. if your class is com.foo.MyImageLoader and located at <build dir>/com/foo/MyImageLoader.class, then the image should be at <build dir>/resources/01.png for you to be able to load it like that.
make sure the resource file is under your class path. For example, check whether your module/project is compiled to xxx.jar and saved under folder "target"
I had this problem as well, when I run mvn install, there is NO jar file generated, that's why no resource found in jar file in target
The cause of no jar generated is caused by following config in pom.xml, remove it and rerun install would be fine.
<packaging>pom</packaging>
If using JDeveloper, make sure that you have the extension of the file that you want copied to the classes folder for use selected. Right click on the project and choose project properties to get to this screen.
I would guess the URL should be "01.png" not "/resources/01.png"

Categories

Resources