Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ij.io().open() raises java.lang.NullPointerException #285

Open
biosciflo opened this issue Sep 11, 2023 · 4 comments
Open

Ij.io().open() raises java.lang.NullPointerException #285

biosciflo opened this issue Sep 11, 2023 · 4 comments

Comments

@biosciflo
Copy link

I don't know if this was fix or not but i ran into the same problem for some images like they describe it here (https://forum.image.sc/t/ij-io-open-raises-java-lang-nullpointerexception/72625)

But its a bit more frustrating for me i have two images in the same location imageA.lsm works fine, but imageB.lsm raises the exception (java.lang.NullPointerException: Cannot invoke "org.scijava.io.location.Location.getName()" because "loc" is null), and when i copy it into the fiji folder than it works. But this is only when I test it on a different windows machine, on my own both images work just fine.

The problem is i want to distribute the program as an standalone (via pyinstaller) and that works just fine on my machine but on others i get these inconsistent problems which is very hard to find out and fix.

@kmilo9999
Copy link

I can confirm this problem still exists.
ij.io().open(path) does not work with full paths. The workaround was to use relative paths instead."

 relative_path = os.path.relpath(full_path)
 image = self.ij.io().open(relative_path)

@ctrueden
Copy link
Member

@kmilo9999 @biosciflo Another workaround:

FileLocation = jimport("org.scijava.io.location.FileLocation")
loc = FileLocation("C:\\path\\to\\image.tif")
dataset = ij.io().open(loc)

ctrueden added a commit to scijava/scijava-common that referenced this issue Aug 27, 2024
Specifically: if the URI resolution returns null, rather than actually
returning null, let's wrap the string into a FileLocation as a fallback.

See imagej/pyimagej#285.
@ctrueden
Copy link
Member

I looked into this issue a bit... is it possible you are both using absolute paths but with forward slashes?

For example: C:/path/to/image.tif. Rather than backslashes? C:\\path\\to\\image.tif?

I can replicate the problematic null location resolution when I use forward slashes. The reason is that it tries to convert the string to a URI, and C:/path/to/image.tif looks like a valid URI with scheme C. 😅

I pushed a tentative fix: scijava/scijava-common@0d95340.

@kmilo9999
Copy link

I looked into this issue a bit... is it possible you are both using absolute paths but with forward slashes?

For example: C:/path/to/image.tif. Rather than backslashes? C:\\path\\to\\image.tif?

I can replicate the problematic null location resolution when I use forward slashes. The reason is that it tries to convert the string to a URI, and C:/path/to/image.tif looks like a valid URI with scheme C. 😅

That might be the reason.
I was using the full path like this:
full path C:/Projects/images/robo5.png

But when I use os.path.relpath(full_path) I get:
relative path ..\images\robo5.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants