Reputation: 23
I am creating an Android app that can filter photos. To perform the image processing necessary for these filters, I use ImageJ's API. The user selects the filters to apply to a photo collection in a dialog box. Upon pressing "OK," however, the app crashes, and the following output appears in LogCat (I'm using Eclipse):
04-07 15:09:24.094: E/AndroidRuntime(14901): FATAL EXCEPTION: main
04-07 15:09:24.094: E/AndroidRuntime(14901): Process: edu.wpi.khufnagle.lighthousenavigator, PID: 14901
04-07 15:09:24.094: E/AndroidRuntime(14901): java.lang.NoClassDefFoundError: ij.io.Opener
04-07 15:09:24.094: E/AndroidRuntime(14901): at edu.wpi.khufnagle.lighthousenavigator.filter.ImageManipulator.validateOriginalImage(ImageManipulator.java:38)
04-07 15:09:24.094: E/AndroidRuntime(14901): at edu.wpi.khufnagle.lighthousenavigator.filter.LighthousePresenceFilter.<init>(LighthousePresenceFilter.java:120)
04-07 15:09:24.094: E/AndroidRuntime(14901): at edu.wpi.khufnagle.lighthousenavigator.filter.PhotographFilter.filterPhotos(PhotographFilter.java:137)
04-07 15:09:24.094: E/AndroidRuntime(14901): at edu.wpi.khufnagle.lighthousenavigator.PhotographsActivity$5.onClick(PhotographsActivity.java:623)
04-07 15:09:24.094: E/AndroidRuntime(14901): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
04-07 15:09:24.094: E/AndroidRuntime(14901): at android.os.Handler.dispatchMessage(Handler.java:102)
As you might guess, the line in question within the validateOriginalImage()
method creates a new Opener
object from ImageJ (used for opening the image as an ImagePlus
object on the following line for later processing).
This exception occurs when I add the "ij.jar" to my app's build path as an external JAR file (on the "Libraries" tab of Eclipse's "Configure Build Path" dialog) or when I include the entire ImageJ source code as a separate Java project in my workspace on the app's build path (on the "Projects" tab). I am using version 1.48 of the "ij.jar" file or version 1.47v of the source code (never both, as that would obviously cause some conflicts during the build process).
In an attempt to solve this problem, I included the ImageJ source code (1.47v as above) within the "src" directory of the app project itself, and I receive a different but equally fatal exception when I attempted to select something in the filtering dialog within the app:
04-07 15:11:07.530: E/AndroidRuntime(29709): FATAL EXCEPTION: main
04-07 15:11:07.530: E/AndroidRuntime(29709): Process: edu.wpi.khufnagle.lighthousenavigator, PID: 29709
04-07 15:11:07.530: E/AndroidRuntime(29709): java.lang.ExceptionInInitializerError
04-07 15:11:07.530: E/AndroidRuntime(29709): at ij.Menus.<clinit>(Menus.java:80)
04-07 15:11:07.530: E/AndroidRuntime(29709): at ij.io.Opener.<clinit>(Opener.java:51)
04-07 15:11:07.530: E/AndroidRuntime(29709): at edu.wpi.khufnagle.lighthousenavigator.filter.ImageManipulator.validateOriginalImage(ImageManipulator.java:38)
.
.
.
04-07 15:11:07.530: E/AndroidRuntime(29709): Caused by: java.lang.StringIndexOutOfBoundsException: length=1; regionStart=0; regionLength=3
04-07 15:11:07.530: E/AndroidRuntime(29709): at java.lang.String.startEndAndLength(String.java:588)
04-07 15:11:07.530: E/AndroidRuntime(29709): at java.lang.String.substring(String.java:1475)
04-07 15:11:07.530: E/AndroidRuntime(29709): at ij.IJ.<clinit>(IJ.java:65)
04-07 15:11:07.530: E/AndroidRuntime(29709): ... 15 more
That StringIndexOutOfBoundsException
is occurring on a line of code in the IJ.java
that checks the version of Java I'm running. Apparently, ImageJ thinks this version string is blank, and when it attempts to take the substring of this (seemingly) blank string, the code throws an exception.
Are there any ImageJ/Eclipse gurus who can help integrate ImageJ into my app successfully?
Upvotes: 2
Views: 1346
Reputation: 84
Be aware that in java you get the java version like this:
System.getProperty(“java.version”)
http://deviltechie.wordpress.com/2011/03/16/get-the-version-of-java-runtime/
But in Android its a bit different:
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
Get application version programmatically in android
That would explain the NoClassDefFoundError
.
Upvotes: 1